//
//  TimeSpaceHistoryView.m
//  Portable Traffic Signal Assistor
//
//  Created by Ding on 10/15/12.
//  Copyright (c) 2012 TTU. All rights reserved.
//

#import "TimeSpaceHistoryView.h"

@implementation TimeSpaceHistoryView

@synthesize dynamicSignalLabelList=_dynamicSignalLabelList;
@synthesize GPSLocationList=_GPSLocationList;
@synthesize cycleTimer=_cycleTimer;
@synthesize direction=_direction;
@synthesize secondsBetweenDates=_secondsBetweenDates;
@synthesize bandLineBeginList=_bandLineBeginList;
@synthesize squareAreaList=_squareAreaList;
@synthesize agency=_agency;
@synthesize timingPattern=_timingPattern;
//@synthesize bandLineEndList=_bandLineEndList;
//@synthesize bandLineColorList=_bandLineColorList;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.backgroundColor=[UIColor clearColor];
        self.secondsBetweenDates=-1;
        self.bandLineBeginList=[[[NSMutableArray alloc] init] autorelease];
        self.squareAreaList=[[[NSMutableArray alloc] init] autorelease];
        //        self.bandLineEndList=[[[NSMutableArray alloc] init] autorelease];
        //        self.bandLineColorList=[[[NSMutableArray alloc] init] autorelease];
    }
    return self;
}

- (void) dealloc
{
    [_dynamicSignalLabelList release];
    [_GPSLocationList release];
    //    [_bandLineEndList release];
    [_bandLineBeginList release];
    [_agency release];
    [_timingPattern release];
    [_squareAreaList release];
    [super dealloc];
}

- (id)initWithFrame:(CGRect)frame dynamicSignalLabelList:(NSMutableArray *)dynamicSignalLabelList direction:(int)direction agency:(Agency *)agency timingPattern:(TimingPattern *)timingPattern
{
    self=[self initWithFrame:frame];
    if (self) {
        self.dynamicSignalLabelList=dynamicSignalLabelList;
        self.backgroundColor=[UIColor clearColor];
        self.secondsBetweenDates=-1;
        self.bandLineBeginList=[[[NSMutableArray alloc] init] autorelease];
        self.squareAreaList=[[[NSMutableArray alloc] init] autorelease];
        //        self.bandLineEndList=[[[NSMutableArray alloc] init] autorelease];
        //        self.bandLineColorList=[[[NSMutableArray alloc] init] autorelease];
        self.direction=direction;
        self.agency=agency;
        self.timingPattern=timingPattern;
        
    }
    return self;
}

- (id)initWithFrame:(CGRect)frame dynamicSignalLabelList:(NSMutableArray *)dynamicSignalLabelList GPSLocationList:(NSMutableArray *)GPSLocationList cycleTimer:(int)cycleTimer direction:(int)direction agency:(Agency *)agency timingPattern:(TimingPattern *)timingPattern
{
    self=[super initWithFrame:frame];
    if (self) {
        self.direction=direction;
        self.dynamicSignalLabelList=dynamicSignalLabelList;
        self.backgroundColor=[UIColor clearColor];
        self.GPSLocationList=GPSLocationList;
        self.cycleTimer=cycleTimer;
        self.secondsBetweenDates=-1;
        self.agency=_agency;
        self.timingPattern=_timingPattern;
        self.bandLineBeginList=[[[NSMutableArray alloc] init] autorelease];
        self.squareAreaList=[[[NSMutableArray alloc] init] autorelease];
        //        self.bandLineEndList=[[[NSMutableArray alloc] init] autorelease];
        //        self.bandLineColorList=[[[NSMutableArray alloc] init] autorelease];
    }
    return self;
}


- (void) updateGPSDraw:(CGContextRef) context offset:(int)offset
{
    CGFloat red[4] = {1.0f, 0.0f, 0.0f, 1.0f};
   CGFloat black[4] = {0.0f, 0.0f, 0.0f, 1.0f};
    //    CGFloat green[4]={0.0f, 1.0f, 0.0f, 1.0f};
    //    CGFloat blue[4]={72.0f/255, 61.0f/255,139.0f/255,1.0f};
    if (self.GPSLocationList.count<=0) {
        return;
    }
    //    CGContextRef context = UIGraphicsGetCurrentContext();
    
    switch (self.direction) {
        case NORTHBOUND:
        case SOUTHBOUND:
        {
            for (GPSEntity *gpsEntity in self.GPSLocationList) {
                CGContextSetLineWidth(context, 5.0);
                CGContextSetStrokeColor(context, black);
                CGContextBeginPath(context);
                CGContextMoveToPoint(context, gpsEntity.NSInterfacePoint.X+offset,gpsEntity.NSInterfacePoint.Y);
                CGContextAddLineToPoint(context, gpsEntity.NSInterfacePoint.X+5+offset,gpsEntity.NSInterfacePoint.Y);
                CGContextStrokePath(context);
            }
        }
            break;
        case EASTBOUND:
        case WESTBOUND:
        {
            for (GPSEntity *gpsEntity in self.GPSLocationList) {
                CGContextSetLineWidth(context, 5.0);
                CGContextSetStrokeColor(context, black);
                CGContextBeginPath(context);
                CGContextMoveToPoint(context, gpsEntity.EWInterfacePoint.X+offset,gpsEntity.EWInterfacePoint.Y);
                CGContextAddLineToPoint(context, gpsEntity.EWInterfacePoint.X+5+offset,gpsEntity.EWInterfacePoint.Y);
                CGContextStrokePath(context);
            }
        }
            break;
        default:
            break;
    }
    
    
    
    
    
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
    [super drawRect:rect];
    [self customizedReDraw];
    
    
}

- (void) customizedReDraw
{
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    //
    //    CGFloat red[4] = {1.0f, 0.0f, 0.0f, 1.0f};
    //    CGFloat green[4]={0.0f, 1.0f, 0.0f, 1.0f};
    CGFloat blue[4]={72.0f/255, 61.0f/255,139.0f/255,1.0f};
    
    
    //draw gps tracks
//    if (self.GPSLocationList.count<=0) {
//        return;
//    }
    //    CLLocation * currentLocation=[self.GPSLocationList objectAtIndex:self.GPSLocationList.count-1];
    double timeToPixel=0;
    if (self.dynamicSignalLabelList.count<=0) {
        return;
    }
    DynamicSignalLabel * label=[self.dynamicSignalLabelList objectAtIndex:0] ;
    timeToPixel=320.0f/[[self.timingPattern cycleLength] intValue];
    //    int locationOffset=0;
    
    {
        NSInteger secondsBetweenDates = round(self.cycleTimer*timeToPixel);
        NSInteger tempSecondsBetweenDates=secondsBetweenDates;
//        if (secondsBetweenDates>280) {
//            secondsBetweenDates=secondsBetweenDates-200;
//            [self updateGPSDraw:context offset:(320-200)];
//        }else
//        {
//            [self updateGPSDraw:context offset:0];
//        }
        [self updateGPSDraw:context offset:0];
        if (self.secondsBetweenDates==-1 || abs(secondsBetweenDates-self.secondsBetweenDates)>100) {
            
//            if (tempSecondsBetweenDates<=280) {
//                for (DynamicSignalLabel* label in self.dynamicSignalLabelList) {
//                    [label updateActivePhaseLabelWithMasterTime:0];
//                    //
//                }
//            }else
//            {
//                //                secondsBetweenDates=secondsBetweenDates-200;
//                for (DynamicSignalLabel* label in self.dynamicSignalLabelList) {
//                    [label updateActivePhaseLabelWithMasterTime:[label.signal.cycleLength intValue]*200/320];
//                    //
//                }
//                //                locationOffset=-200;
//            }
            
            
            self.secondsBetweenDates=secondsBetweenDates;
            self.bandLineBeginList=[[[NSMutableArray alloc] init] autorelease];
//            [self updateGPSDraw:context];
            
            
        }else
        {
            self.secondsBetweenDates=secondsBetweenDates;
            for (InterfaceLine *line in self.bandLineBeginList) {
                CGContextSetLineWidth(context, 2.0);
                CGContextSetStrokeColor(context,CGColorGetComponents(line.color.CGColor));
                CGContextBeginPath(context);
                CGContextMoveToPoint(context, line.beginPoint.X,line.beginPoint.Y);
                CGContextAddLineToPoint(context, line.endPoint.X,line.endPoint.Y);
                CGContextStrokePath(context);
            }
            for (InterfaceSquareArea *square in self.squareAreaList) {
                const float* colors = CGColorGetComponents(square.color.CGColor);
                CGContextSetRGBFillColor(context, colors[0], colors[1],colors[2], colors[3]);
                CGContextBeginPath(context);
                CGContextMoveToPoint   (context, square.topLeftPoint.X, square.topLeftPoint.Y);
                CGContextAddLineToPoint(context, square.topRightPoint.X, square.topRightPoint.Y);
                CGContextAddLineToPoint(context, square.bottomRightPoint.X, square.bottomRightPoint.Y);
                CGContextAddLineToPoint(context, square.bottomLeftPoint.X, square.bottomLeftPoint.Y);
                CGContextClosePath(context);
                
                CGContextFillPath(context);
                
            }
            
            
//            [self updateGPSDraw:context];
            //draw time line
            CGContextSetLineWidth(context, 2.0);
            CGContextSetStrokeColor(context, blue);
            
            CGContextBeginPath(context);
            CGContextMoveToPoint(context, secondsBetweenDates, 0);
            CGContextAddLineToPoint(context, secondsBetweenDates, self.frame.size.height);
            CGContextStrokePath(context);
            return;
            
        }
        //draw time line
        CGContextSetLineWidth(context, 2.0);
        CGContextSetStrokeColor(context, blue);
        
        CGContextBeginPath(context);
        CGContextMoveToPoint(context, secondsBetweenDates, 0);
        CGContextAddLineToPoint(context, secondsBetweenDates, self.frame.size.height);
        CGContextStrokePath(context);
        
    }
    
    
    
    
    if (self.dynamicSignalLabelList.count<2) {
        return;
    }
    
    
    
    InterfacePoint *bandLeftBeginPoint=[[[InterfacePoint alloc] initWithXY:0 Y:0] autorelease];
    InterfacePoint *bandLeftEndPoint=[[[InterfacePoint alloc] initWithXY:0 Y:0] autorelease];
    InterfacePoint *bandRightBeginPoint=[[[InterfacePoint alloc] initWithXY:0 Y:0] autorelease];
    InterfacePoint *bandRightEndPoint=[[[InterfacePoint alloc] initWithXY:0 Y:0] autorelease];
    
    //    DynamicSignalLabel *lastLabel=[self.dynamicSignalLabelList objectAtIndex:0];
    
    
    CGContextSetLineWidth(context, 2.0);
    for (int i=0; i<self.dynamicSignalLabelList.count; i++) {
        DynamicSignalLabel *label=[self.dynamicSignalLabelList objectAtIndex:i];
        //        Link *beforeLink=label.beforeLink;
        switch (self.direction) {
            case NORTHBOUND:
            case SOUTHBOUND:
                //Northbound
            {
                Link *beforeLink=label.beforeLink;
                Link *afterLink=label.afterLink;
                if (beforeLink) {
                    DynamicSignalLabel *nextLabel=[self.dynamicSignalLabelList objectAtIndex:i-1];
                    
                    for (int k=0;k< label.nbandLeftBeginPoints.count;k++) {
                        InterfacePoint *point =[label.nbandLeftEndPoints objectAtIndex:k];
                        InterfacePoint *endPoint=[label.nbandRightEndPoints objectAtIndex:k];
                        
                        bandLeftBeginPoint.X=point.X;
                        bandLeftBeginPoint.Y=point.Y+label.frame.origin.y;
                        bandLeftEndPoint.X=point.X+[beforeLink getOffsetX]*timeToPixel;
                        bandLeftEndPoint.Y=point.Y-[beforeLink getOffsetY]+label.frame.origin.y;
                        
                        bandRightBeginPoint.X=endPoint.X;
                        bandRightBeginPoint.Y=endPoint.Y+label.frame.origin.y;
                        bandRightEndPoint.X=endPoint.X+[beforeLink getOffsetX]*timeToPixel;
                        bandRightEndPoint.Y=endPoint.Y-[beforeLink getOffsetY]+label.frame.origin.y;
                        //                BOOL leftArriveAtGreen=NO;
                        
                        {
                            int j=0;
                            if (nextLabel.nbandLeftBeginPoints.count>0) {
                                InterfacePoint *rightPoint=[nextLabel.nbandLeftBeginPoints objectAtIndex:j];
                                InterfacePoint *leftPoint=[[[InterfacePoint alloc] initWithXY:nextLabel.frame.origin.x Y:nextLabel.frame.origin.y+nextLabel.frame.size.height] autorelease];
                                //For the situation that the band left end point arrivies the next signal at red.
                                if (bandLeftEndPoint.X>leftPoint.X && bandLeftEndPoint.X<rightPoint.X) {
                                    bandLeftBeginPoint.X=bandLeftBeginPoint.X+(rightPoint.X- bandLeftEndPoint.X);
                                    bandLeftEndPoint.X=bandLeftEndPoint.X+(rightPoint.X- bandLeftEndPoint.X);
                                }
                                
                                //                        break;
                            }else
                            {
                                break;
                            }
                            //                    if (bandRightEndPoint.X>leftPoint.X && bandRightEndPoint.X<rightPoint.X) {
                            //                        bandRightBeginPoint.X=bandRightBeginPoint.X-(bandRightEndPoint.X-leftPoint.X);
                            //                        bandRightEndPoint.X=bandRightEndPoint.X-(bandRightEndPoint.X-leftPoint.X);
                            //                        //                        break;
                            //                    }
                        }
                        for (int j=1; j<nextLabel.nbandLeftEndPoints.count; j++) {
                            InterfacePoint *rightPoint=[nextLabel.nbandLeftEndPoints objectAtIndex:j];
                            InterfacePoint *leftPoint=[nextLabel.nbandRightEndPoints objectAtIndex:j-1];
                            
                            if (bandLeftEndPoint.X>leftPoint.X && bandLeftEndPoint.X<rightPoint.X) {
                                bandLeftBeginPoint.X=bandLeftBeginPoint.X+(rightPoint.X- bandLeftEndPoint.X);
                                bandLeftEndPoint.X=bandLeftEndPoint.X+(rightPoint.X- bandLeftEndPoint.X);
                                //                        break;
                            }
                            if (bandRightEndPoint.X>leftPoint.X && bandRightEndPoint.X<rightPoint.X) {
                                bandRightBeginPoint.X=bandRightBeginPoint.X-(bandRightEndPoint.X-leftPoint.X);
                                bandRightEndPoint.X=bandRightEndPoint.X-(bandRightEndPoint.X-leftPoint.X);
                                //                        break;
                            }
                            
                        }
                        {
                            int j=nextLabel.nbandLeftEndPoints.count-1;
                            InterfacePoint *rightPoint=[[[InterfacePoint alloc] initWithXY:nextLabel.frame.origin.x+nextLabel.frame.size.width Y:nextLabel.frame.origin.y+nextLabel.frame.size.height] autorelease];
                            if (nextLabel.nbandRightEndPoints.count>0) {
                                InterfacePoint *leftPoint=[nextLabel.nbandRightEndPoints objectAtIndex:j];
                                
                                //                    if (bandLeftEndPoint.X>leftPoint.X && bandLeftEndPoint.X<rightPoint.X) {
                                //                        bandLeftBeginPoint.X=bandLeftBeginPoint.X+(rightPoint.X- bandLeftEndPoint.X);
                                //                        bandLeftEndPoint.X=bandLeftEndPoint.X+(rightPoint.X- bandLeftEndPoint.X);
                                //                        //                        break;
                                //                    }
                                if (bandRightEndPoint.X>leftPoint.X && bandRightEndPoint.X<rightPoint.X) {
                                    bandRightBeginPoint.X=bandRightBeginPoint.X-(bandRightEndPoint.X-leftPoint.X);
                                    bandRightEndPoint.X=bandRightEndPoint.X-(bandRightEndPoint.X-leftPoint.X);
                                    //                        break;
                                }
                            }else
                            {
                                break;
                            }
                        }
                        //                for (int j=1; j<nextLabel.bandLeftEndPoints.count; j++) {
                        //                    InterfacePoint *rightPoint=[nextLabel.bandLeftEndPoints objectAtIndex:j];
                        //                    InterfacePoint *leftPoint=[nextLabel.bandRightEndPoints objectAtIndex:j-1];
                        //
                        //
                        //                }
                        
                        
                        if (bandLeftBeginPoint.X<=bandRightBeginPoint.X) {
                            
                            Link *aLink=nextLabel.afterLink;
                            //                    Link *aLink=nextLabel.afterLink;
                            BOOL bandWasIntterupted=NO;
                            if (aLink) {
                                for (int m=0;m<nextLabel.nbandLeftBeginPoints.count;m++) {
                                    InterfacePoint *leftpoint=[nextLabel.nbandLeftBeginPoints objectAtIndex:m];
                                    InterfacePoint *rightPoint=[nextLabel.nbandrightBeginPoints objectAtIndex:m];
                                    //if the next signal has a red during the band.
                                    if (leftpoint.X>bandLeftEndPoint.X &&leftpoint.X<bandRightEndPoint.X) {
                                        InterfacePoint *lineBeginPoint=[[[InterfacePoint alloc] initWithXY:leftpoint.X Y:leftpoint.Y+nextLabel.frame.origin.y] autorelease];
                                        InterfacePoint *lineEndPoint=[[[InterfacePoint alloc] initWithXY:leftpoint.X-[aLink getOffsetX]*timeToPixel Y:leftpoint.Y+[aLink getOffsetY]+nextLabel.frame.origin.y] autorelease];
                                        UIColor *lineColor=[UIColor blueColor];
                                        InterfaceLine * interfaceLine=[[[InterfaceLine alloc] initWithBeginPoint:lineBeginPoint endPoint:lineEndPoint color:lineColor] autorelease];
                                        CGContextSetLineWidth(context, 2.0);
                                        CGContextSetStrokeColor(context, CGColorGetComponents(lineColor.CGColor));
                                        CGContextBeginPath(context);
                                        //                                CGContextMoveToPoint(context, leftpoint.X, leftpoint.Y+nextLabel.frame.origin.y);
                                        CGContextMoveToPoint(context, interfaceLine.beginPoint.X,interfaceLine.beginPoint.Y);
                                        //                                CGContextAddLineToPoint(context, leftpoint.X-[bLink getOffsetX], leftpoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y);
                                        CGContextAddLineToPoint(context, interfaceLine.endPoint.X, interfaceLine.endPoint.Y);
                                        CGContextStrokePath(context);
                                        [self.bandLineBeginList addObject:interfaceLine];
                                        
                                        
                                        
                                        
                                        InterfacePoint *lineBeginPoint2=[[[InterfacePoint alloc] initWithXY:bandRightBeginPoint.X Y:bandRightBeginPoint.Y]autorelease];
                                        InterfacePoint *lineEndPoint2=[[[InterfacePoint alloc] initWithXY:bandRightEndPoint.X Y:bandRightEndPoint.Y]autorelease];;
                                        const float* colors = CGColorGetComponents(lineColor.CGColor);
                                        UIColor *squareColor=[UIColor colorWithRed:colors[0] green:colors[1] blue:colors[2] alpha:0.5];
                                        
                                        CGContextSetRGBFillColor(context, colors[0], colors[1],colors[2], 0.5);
                                        InterfaceSquareArea *square=[[InterfaceSquareArea alloc] initWithTopLeftPoint:lineEndPoint topRightPoint:lineBeginPoint2 bottomLeftPoint:lineBeginPoint bottomRightPoint:lineEndPoint2 color:squareColor];
                                        CGContextBeginPath(context);
                                        CGContextMoveToPoint   (context, square.topLeftPoint.X, square.topLeftPoint.Y);
                                        CGContextAddLineToPoint(context, square.topRightPoint.X, square.topRightPoint.Y);
                                        CGContextAddLineToPoint(context, square.bottomRightPoint.X, square.bottomRightPoint.Y);
                                        CGContextAddLineToPoint(context, square.bottomLeftPoint.X, square.bottomLeftPoint.Y);
                                        CGContextClosePath(context);
                                        
                                        CGContextFillPath(context);
                                        [self.squareAreaList addObject:square];
                                        bandWasIntterupted=YES;
                                        //                                [self.bandLineEndList addObject:[[[InterfacePoint alloc] initWithXY:leftpoint.X-[bLink getOffsetX] Y:leftpoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y] autorelease]];
                                        //                                [self.bandLineColorList addObject:[UIColor greenColor]];
                                        
                                    }
                                    if (rightPoint.X>bandLeftEndPoint.X &&rightPoint.X<bandRightEndPoint.X) {
                                        
                                        InterfacePoint *lineBeginPoint=[[[InterfacePoint alloc] initWithXY:rightPoint.X Y:rightPoint.Y+nextLabel.frame.origin.y] autorelease];
                                        InterfacePoint *lineEndPoint=[[[InterfacePoint alloc] initWithXY:rightPoint.X-[aLink getOffsetX]*timeToPixel Y:rightPoint.Y+[aLink getOffsetY]+nextLabel.frame.origin.y] autorelease];
//                                        UIColor *lineColor=[UIColor redColor];
                                        UIColor *lineColor=[UIColor blueColor];
                                        InterfaceLine * interfaceLine=[[[InterfaceLine alloc] initWithBeginPoint:lineBeginPoint endPoint:lineEndPoint color:lineColor] autorelease];
                                        
                                        CGContextSetLineWidth(context, 2.0);
                                        CGContextSetStrokeColor(context, CGColorGetComponents(lineColor.CGColor));
                                        CGContextBeginPath(context);
                                        //                                CGContextMoveToPoint(context, rightPoint.X, rightPoint.Y+nextLabel.frame.origin.y);
                                        CGContextMoveToPoint(context, interfaceLine.beginPoint.X, interfaceLine.beginPoint.Y);
                                        //                                CGContextAddLineToPoint(context, rightPoint.X-[bLink getOffsetX], rightPoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y);
                                        CGContextAddLineToPoint(context, interfaceLine.endPoint.X, interfaceLine.endPoint.Y);
                                        
                                        CGContextStrokePath(context);
                                        [self.bandLineBeginList addObject:interfaceLine];
                                        
                                        
                                        
                                        
                                        InterfacePoint *lineBeginPoint2=[[[InterfacePoint alloc] initWithXY:bandLeftBeginPoint.X Y:bandLeftBeginPoint.Y]autorelease];
                                        InterfacePoint *lineEndPoint2=[[[InterfacePoint alloc] initWithXY:bandLeftEndPoint.X Y:bandLeftEndPoint.Y]autorelease];;
                                        const float* colors = CGColorGetComponents(lineColor.CGColor);
                                        UIColor *squareColor=[UIColor colorWithRed:colors[0] green:colors[1] blue:colors[2] alpha:0.5];
                                        
                                        CGContextSetRGBFillColor(context, colors[0], colors[1],colors[2], 0.5);
                                        InterfaceSquareArea *square=[[InterfaceSquareArea alloc] initWithTopLeftPoint:lineBeginPoint2 topRightPoint:lineEndPoint bottomLeftPoint:lineEndPoint2 bottomRightPoint:lineBeginPoint color:squareColor];
                                        CGContextBeginPath(context);
                                        CGContextMoveToPoint   (context, square.topLeftPoint.X, square.topLeftPoint.Y);
                                        CGContextAddLineToPoint(context, square.topRightPoint.X, square.topRightPoint.Y);
                                        CGContextAddLineToPoint(context, square.bottomRightPoint.X, square.bottomRightPoint.Y);
                                        CGContextAddLineToPoint(context, square.bottomLeftPoint.X, square.bottomLeftPoint.Y);
                                        CGContextClosePath(context);
                                        
                                        CGContextFillPath(context);
                                        [self.squareAreaList addObject:square];
                                        bandWasIntterupted=YES;

                                        //                                [self.bandLineBeginList addObject:[[[InterfacePoint alloc] initWithXY:rightPoint.X Y:rightPoint.Y+nextLabel.frame.origin.y] autorelease]];
                                        //
                                        //                                [self.bandLineEndList addObject:[[[InterfacePoint alloc] initWithXY:rightPoint.X-[bLink getOffsetX] Y:rightPoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y] autorelease]];
                                        //                                [self.bandLineColorList addObject:[UIColor redColor]];
                                        
                                    }
                                    
                                    
                                }
                            }
                            
                            InterfacePoint *lineBeginPoint=[[[InterfacePoint alloc] initWithXY:bandLeftBeginPoint.X Y:bandLeftBeginPoint.Y]autorelease];
                            InterfacePoint *lineEndPoint=[[[InterfacePoint alloc] initWithXY:bandLeftEndPoint.X Y:bandLeftEndPoint.Y]autorelease];;
                            UIColor *lineColor=[UIColor blueColor];
                            InterfaceLine * interfaceLine=[[[InterfaceLine alloc] initWithBeginPoint:lineBeginPoint endPoint:lineEndPoint color:lineColor] autorelease];
                            
                            CGContextSetLineWidth(context, 2.0);
                            CGContextSetStrokeColor(context, CGColorGetComponents(lineColor.CGColor));
                            CGContextBeginPath(context);
                            //                    CGContextMoveToPoint(context, bandLeftBeginPoint.X, bandLeftBeginPoint.Y);
                            CGContextMoveToPoint(context, interfaceLine.beginPoint.X, interfaceLine.beginPoint.Y);
                            
                            //                    CGContextAddLineToPoint(context, bandLeftEndPoint.X,bandLeftEndPoint.Y);
                            CGContextAddLineToPoint(context, interfaceLine.endPoint.X,interfaceLine.endPoint.Y);
                            CGContextStrokePath(context);
                            
                            [self.bandLineBeginList addObject:interfaceLine];
                            NSLog(@"\\nbeginPointX=%f,beginPointY=%f,endPointX=%f,endPointY=%f",interfaceLine.beginPoint.X,interfaceLine.beginPoint.Y,interfaceLine.endPoint.X,interfaceLine.endPoint.Y);
                            
                            //                    [self.bandLineEndList addObject:[[[InterfacePoint alloc] initWithXY:bandLeftEndPoint.X Y:bandLeftEndPoint.Y] autorelease]];
                            
                            //                    [self.bandLineColorList addObject:[UIColor greenColor]];
                            
                            
                            
                            
                            InterfacePoint *lineBeginPoint2=[[[InterfacePoint alloc] initWithXY:bandRightBeginPoint.X Y:bandRightBeginPoint.Y]autorelease];
                            InterfacePoint *lineEndPoint2=[[[InterfacePoint alloc] initWithXY:bandRightEndPoint.X Y:bandRightEndPoint.Y]autorelease];;
//                            UIColor *lineColor2=[UIColor redColor];
                            UIColor *lineColor2=[UIColor blueColor];
                            InterfaceLine * line2=[[[InterfaceLine alloc] initWithBeginPoint:lineBeginPoint2 endPoint:lineEndPoint2 color:lineColor2] autorelease];
                            CGContextSetLineWidth(context, 2.0);
                            CGContextSetStrokeColor(context, CGColorGetComponents(lineColor2.CGColor));
                            CGContextBeginPath(context);
                            //                    CGContextMoveToPoint(context, bandRightBeginPoint.X, bandRightBeginPoint.Y);
                            CGContextMoveToPoint(context, line2.beginPoint.X, line2.beginPoint.Y);
                            //                    CGContextAddLineToPoint(context, bandRightEndPoint.X,bandRightEndPoint.Y);
                            CGContextAddLineToPoint(context, line2.endPoint.X,line2.endPoint.Y);
                            CGContextStrokePath(context);
                            [self.bandLineBeginList addObject:line2];
                            NSLog(@"\\nbeginPointX=%f,beginPointY=%f,endPointX=%f,endPointY=%f",line2.beginPoint.X,line2.beginPoint.Y,line2.endPoint.X,line2.endPoint.Y);
                            
                            //                    [self.bandLineEndList addObject:[[[InterfacePoint alloc] initWithXY:bandRightEndPoint.X Y:bandRightEndPoint.Y] autorelease]];
                            
                            //                    [self.bandLineColorList addObject:[UIColor redColor]];
                            if (!bandWasIntterupted) {
                                const float* colors = CGColorGetComponents(lineColor2.CGColor);
                                UIColor *squareColor=[UIColor colorWithRed:colors[0] green:colors[1] blue:colors[2] alpha:0.5];
                                
                                CGContextSetRGBFillColor(context, colors[0], colors[1],colors[2], 0.5);
                                InterfaceSquareArea *square=[[InterfaceSquareArea alloc] initWithTopLeftPoint:lineBeginPoint topRightPoint:lineBeginPoint2 bottomLeftPoint:lineEndPoint bottomRightPoint:lineEndPoint2 color:squareColor];
                                CGContextBeginPath(context);
                                CGContextMoveToPoint   (context, square.topLeftPoint.X, square.topLeftPoint.Y);
                                CGContextAddLineToPoint(context, square.topRightPoint.X, square.topRightPoint.Y);
                                CGContextAddLineToPoint(context, square.bottomRightPoint.X, square.bottomRightPoint.Y);
                                CGContextAddLineToPoint(context, square.bottomLeftPoint.X, square.bottomLeftPoint.Y);
                                CGContextClosePath(context);
                                
                                CGContextFillPath(context);
                                [self.squareAreaList addObject:square];
                            }
                        }
                        
                        
                    }
                }
                if(afterLink)
                {
                    for (int k=0;k< label.nbandLeftEndPoints.count;k++) {
                        {
                            InterfacePoint *point =[label.nbandLeftEndPoints objectAtIndex:k];
                            InterfacePoint *endPoint=[label.nbandRightEndPoints objectAtIndex:k];
                            
                            Link *afterLink=label.afterLink;
                            if (!afterLink) {
                                continue;
                            }
                            
                            InterfacePoint *tempBandLeftBeginPoint=[[[InterfacePoint alloc] initWithXY:0 Y:0] autorelease];
                            InterfacePoint *tempBandLeftEndPoint=[[[InterfacePoint alloc] initWithXY:0 Y:0] autorelease];
                            InterfacePoint *tempBandRightBeginPoint=[[[InterfacePoint alloc] initWithXY:0 Y:0] autorelease];
                            InterfacePoint *tempBandRightEndPoint=[[[InterfacePoint alloc] initWithXY:0 Y:0] autorelease];
                            
                            {
                                tempBandLeftBeginPoint.X=point.X;
                                tempBandLeftBeginPoint.Y=point.Y+label.frame.origin.y+label.signalNameLabel.frame.size.height;
                                tempBandLeftEndPoint.X=point.X-[afterLink getOffsetX]*timeToPixel;
                                tempBandLeftEndPoint.Y=point.Y+[afterLink getOffsetY]+label.frame.origin.y+label.signalNameLabel.frame.size.height;
                                
                                tempBandRightBeginPoint.X=endPoint.X;
                                tempBandRightBeginPoint.Y=endPoint.Y+label.frame.origin.y+label.signalNameLabel.frame.size.height;
                                tempBandRightEndPoint.X=endPoint.X-[afterLink getOffsetX]*timeToPixel;
                                tempBandRightEndPoint.Y=endPoint.Y+[afterLink getOffsetY]+label.frame.origin.y+label.signalNameLabel.frame.size.height;
                                
                                UIColor *lineColor=[UIColor blueColor];
                                InterfaceLine * interfaceLine=[[[InterfaceLine alloc] initWithBeginPoint:tempBandLeftBeginPoint endPoint:tempBandLeftEndPoint color:lineColor] autorelease];
                                CGContextSetLineWidth(context, 2.0);
                                CGContextSetStrokeColor(context, CGColorGetComponents(lineColor.CGColor));
                                CGContextBeginPath(context);
                                //                                CGContextMoveToPoint(context, leftpoint.X, leftpoint.Y+nextLabel.frame.origin.y);
                                CGFloat dashArray[] = {2,6,4,2};
                                
                                CGContextSetLineDash(context, 3, dashArray, 4);
                                interfaceLine.dashed=YES;
                                CGContextMoveToPoint(context, interfaceLine.beginPoint.X,interfaceLine.beginPoint.Y);
                                //                                CGContextAddLineToPoint(context, leftpoint.X-[bLink getOffsetX], leftpoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y);
                                CGContextAddLineToPoint(context, interfaceLine.endPoint.X, interfaceLine.endPoint.Y);
                                CGContextStrokePath(context);
                                [self.bandLineBeginList addObject:interfaceLine];
                                CGContextSetLineDash(context, 0, nil, 0);
                            }
                            {
                                tempBandLeftBeginPoint.X=point.X;
                                tempBandLeftBeginPoint.Y=point.Y+label.frame.origin.y+label.signalNameLabel.frame.size.height;
                                tempBandLeftEndPoint.X=point.X-[afterLink getOffsetX]*timeToPixel;
                                tempBandLeftEndPoint.Y=point.Y+[afterLink getOffsetY]+label.frame.origin.y+label.signalNameLabel.frame.size.height;
                                
                                tempBandRightBeginPoint.X=endPoint.X;
                                tempBandRightBeginPoint.Y=endPoint.Y+label.frame.origin.y+label.signalNameLabel.frame.size.height;
                                tempBandRightEndPoint.X=endPoint.X-[afterLink getOffsetX]*timeToPixel;
                                tempBandRightEndPoint.Y=endPoint.Y+[afterLink getOffsetY]+label.frame.origin.y+label.signalNameLabel.frame.size.height;
                                
                                UIColor *lineColor=[UIColor blueColor];
                                InterfaceLine * interfaceLine=[[[InterfaceLine alloc] initWithBeginPoint:tempBandRightBeginPoint endPoint:tempBandRightEndPoint color:lineColor] autorelease];
                                CGContextSetLineWidth(context, 2.0);
                                CGContextSetStrokeColor(context, CGColorGetComponents(lineColor.CGColor));
                                CGContextBeginPath(context);
                                //                                CGContextMoveToPoint(context, leftpoint.X, leftpoint.Y+nextLabel.frame.origin.y);
                                CGFloat dashArray[] = {2,6,4,2};
                                
                                CGContextSetLineDash(context, 3, dashArray, 4);
                                interfaceLine.dashed=YES;
                                CGContextMoveToPoint(context, interfaceLine.beginPoint.X,interfaceLine.beginPoint.Y);
                                //                                CGContextAddLineToPoint(context, leftpoint.X-[bLink getOffsetX], leftpoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y);
                                CGContextAddLineToPoint(context, interfaceLine.endPoint.X, interfaceLine.endPoint.Y);
                                CGContextStrokePath(context);
                                [self.bandLineBeginList addObject:interfaceLine];
                                CGContextSetLineDash(context, 0, nil, 0);
                            }
                            
                            
                        }
                    }
                }
            }
                //Southbound
            {
                Link *afterLink=label.afterLink;
                Link *beforeLink=label.beforeLink;
                if (afterLink) {
                    DynamicSignalLabel *nextLabel=[self.dynamicSignalLabelList objectAtIndex:i+1];
                    
                    for (int k=0;k< label.sbandLeftBeginPoints.count;k++) {
                        InterfacePoint *point =[label.sbandLeftBeginPoints objectAtIndex:k];
                        InterfacePoint *endPoint=[label.sbandrightBeginPoints objectAtIndex:k];
                        
                        bandLeftBeginPoint.X=point.X;
                        bandLeftBeginPoint.Y=point.Y+label.frame.origin.y;
                        bandLeftEndPoint.X=point.X+[afterLink getOffsetX]*timeToPixel;
                        bandLeftEndPoint.Y=point.Y+[afterLink getOffsetY]+label.frame.origin.y;
                        
                        bandRightBeginPoint.X=endPoint.X;
                        bandRightBeginPoint.Y=endPoint.Y+label.frame.origin.y;
                        bandRightEndPoint.X=endPoint.X+[afterLink getOffsetX]*timeToPixel;
                        bandRightEndPoint.Y=endPoint.Y+[afterLink getOffsetY]+label.frame.origin.y;
                        //                BOOL leftArriveAtGreen=NO;
                        
                        {
                            int j=0;
                            if (nextLabel.sbandLeftEndPoints.count>0) {
                                InterfacePoint *rightPoint=[nextLabel.sbandLeftEndPoints objectAtIndex:j];
                                InterfacePoint *leftPoint=[[[InterfacePoint alloc] initWithXY:nextLabel.frame.origin.x Y:nextLabel.frame.origin.y] autorelease];
                                
                                if (bandLeftEndPoint.X>leftPoint.X && bandLeftEndPoint.X<rightPoint.X) {
                                    bandLeftBeginPoint.X=bandLeftBeginPoint.X+(rightPoint.X- bandLeftEndPoint.X);
                                    bandLeftEndPoint.X=bandLeftEndPoint.X+(rightPoint.X- bandLeftEndPoint.X);
                                    //                        break;
                                }
                            }else
                            {
                                break;
                            }
                            //                    if (bandRightEndPoint.X>leftPoint.X && bandRightEndPoint.X<rightPoint.X) {
                            //                        bandRightBeginPoint.X=bandRightBeginPoint.X-(bandRightEndPoint.X-leftPoint.X);
                            //                        bandRightEndPoint.X=bandRightEndPoint.X-(bandRightEndPoint.X-leftPoint.X);
                            //                        //                        break;
                            //                    }
                        }
                        for (int j=1; j<nextLabel.sbandLeftEndPoints.count; j++) {
                            InterfacePoint *rightPoint=[nextLabel.sbandLeftEndPoints objectAtIndex:j];
                            InterfacePoint *leftPoint=[nextLabel.sbandRightEndPoints objectAtIndex:j-1];
                            
                            if (bandLeftEndPoint.X>leftPoint.X && bandLeftEndPoint.X<rightPoint.X) {
                                bandLeftBeginPoint.X=bandLeftBeginPoint.X+(rightPoint.X- bandLeftEndPoint.X);
                                bandLeftEndPoint.X=bandLeftEndPoint.X+(rightPoint.X- bandLeftEndPoint.X);
                                //                        break;
                            }
                            if (bandRightEndPoint.X>leftPoint.X && bandRightEndPoint.X<rightPoint.X) {
                                bandRightBeginPoint.X=bandRightBeginPoint.X-(bandRightEndPoint.X-leftPoint.X);
                                bandRightEndPoint.X=bandRightEndPoint.X-(bandRightEndPoint.X-leftPoint.X);
                                //                        break;
                            }
                            
                        }
                        {
                            int j=nextLabel.sbandLeftEndPoints.count-1;
                            InterfacePoint *rightPoint=[[[InterfacePoint alloc] initWithXY:nextLabel.frame.origin.x+nextLabel.frame.size.width Y:nextLabel.frame.origin.y] autorelease];
                            if (nextLabel.sbandRightEndPoints.count>0) {
                                InterfacePoint *leftPoint=[nextLabel.sbandRightEndPoints objectAtIndex:j];
                                
                                //                    if (bandLeftEndPoint.X>leftPoint.X && bandLeftEndPoint.X<rightPoint.X) {
                                //                        bandLeftBeginPoint.X=bandLeftBeginPoint.X+(rightPoint.X- bandLeftEndPoint.X);
                                //                        bandLeftEndPoint.X=bandLeftEndPoint.X+(rightPoint.X- bandLeftEndPoint.X);
                                //                        //                        break;
                                //                    }
                                if (bandRightEndPoint.X>leftPoint.X && bandRightEndPoint.X<rightPoint.X) {
                                    bandRightBeginPoint.X=bandRightBeginPoint.X-(bandRightEndPoint.X-leftPoint.X);
                                    bandRightEndPoint.X=bandRightEndPoint.X-(bandRightEndPoint.X-leftPoint.X);
                                    //                        break;
                                }
                            }else
                            {
                                break;
                            }
                        }
                        //                for (int j=1; j<nextLabel.bandLeftEndPoints.count; j++) {
                        //                    InterfacePoint *rightPoint=[nextLabel.bandLeftEndPoints objectAtIndex:j];
                        //                    InterfacePoint *leftPoint=[nextLabel.bandRightEndPoints objectAtIndex:j-1];
                        //
                        //
                        //                }
                        
                        
                        if (bandLeftBeginPoint.X<=bandRightBeginPoint.X) {
                            
                            Link *bLink=nextLabel.beforeLink;
                            //                    Link *aLink=nextLabel.afterLink;
                            BOOL bandWasIntterupted=NO;
                            if (bLink) {
                                for (int m=0;m<nextLabel.sbandLeftEndPoints.count;m++) {
                                    InterfacePoint *leftpoint=[nextLabel.sbandLeftEndPoints objectAtIndex:m];
                                    InterfacePoint *rightPoint=[nextLabel.sbandRightEndPoints objectAtIndex:m];
                                    if (leftpoint.X>bandLeftEndPoint.X &&leftpoint.X<bandRightEndPoint.X) {
                                        InterfacePoint *lineBeginPoint=[[[InterfacePoint alloc] initWithXY:leftpoint.X Y:leftpoint.Y+nextLabel.frame.origin.y] autorelease];
                                        InterfacePoint *lineEndPoint=[[[InterfacePoint alloc] initWithXY:leftpoint.X-[bLink getOffsetX]*timeToPixel Y:leftpoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y] autorelease];
                                        UIColor *lineColor=[UIColor greenColor];
                                        InterfaceLine * interfaceLine=[[[InterfaceLine alloc] initWithBeginPoint:lineBeginPoint endPoint:lineEndPoint color:lineColor] autorelease];
                                        CGContextSetLineWidth(context, 2.0);
                                        CGContextSetStrokeColor(context, CGColorGetComponents(lineColor.CGColor));
                                        CGContextBeginPath(context);
                                        //                                CGContextMoveToPoint(context, leftpoint.X, leftpoint.Y+nextLabel.frame.origin.y);
                                        CGContextMoveToPoint(context, interfaceLine.beginPoint.X,interfaceLine.beginPoint.Y);
                                        //                                CGContextAddLineToPoint(context, leftpoint.X-[bLink getOffsetX], leftpoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y);
                                        CGContextAddLineToPoint(context, interfaceLine.endPoint.X, interfaceLine.endPoint.Y);
                                        CGContextStrokePath(context);
                                        [self.bandLineBeginList addObject:interfaceLine];
                                        
                                        
                                        
                                        
                                        InterfacePoint *lineBeginPoint2=[[[InterfacePoint alloc] initWithXY:bandRightBeginPoint.X Y:bandRightBeginPoint.Y]autorelease];
                                        InterfacePoint *lineEndPoint2=[[[InterfacePoint alloc] initWithXY:bandRightEndPoint.X Y:bandRightEndPoint.Y]autorelease];;
                                        const float* colors = CGColorGetComponents(lineColor.CGColor);
                                        UIColor *squareColor=[UIColor colorWithRed:colors[0] green:colors[1] blue:colors[2] alpha:0.5];
                                        
                                        CGContextSetRGBFillColor(context, colors[0], colors[1],colors[2], 0.5);
                                        InterfaceSquareArea *square=[[InterfaceSquareArea alloc] initWithTopLeftPoint:lineEndPoint topRightPoint:lineBeginPoint2 bottomLeftPoint:lineBeginPoint bottomRightPoint:lineEndPoint2 color:squareColor];
                                        CGContextBeginPath(context);
                                        CGContextMoveToPoint   (context, square.topLeftPoint.X, square.topLeftPoint.Y);
                                        CGContextAddLineToPoint(context, square.topRightPoint.X, square.topRightPoint.Y);
                                        CGContextAddLineToPoint(context, square.bottomRightPoint.X, square.bottomRightPoint.Y);
                                        CGContextAddLineToPoint(context, square.bottomLeftPoint.X, square.bottomLeftPoint.Y);
                                        CGContextClosePath(context);
                                        
                                        CGContextFillPath(context);
                                        [self.squareAreaList addObject:square];
                                        bandWasIntterupted=YES;
                                        //                                [self.bandLineEndList addObject:[[[InterfacePoint alloc] initWithXY:leftpoint.X-[bLink getOffsetX] Y:leftpoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y] autorelease]];
                                        //                                [self.bandLineColorList addObject:[UIColor greenColor]];
                                        
                                    }
                                    if (rightPoint.X>bandLeftEndPoint.X &&rightPoint.X<bandRightEndPoint.X) {
                                        
                                        InterfacePoint *lineBeginPoint=[[[InterfacePoint alloc] initWithXY:rightPoint.X Y:rightPoint.Y+nextLabel.frame.origin.y] autorelease];
                                        InterfacePoint *lineEndPoint=[[[InterfacePoint alloc] initWithXY:rightPoint.X-[bLink getOffsetX]*timeToPixel Y:rightPoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y] autorelease];
//                                        UIColor *lineColor=[UIColor redColor];
                                        UIColor *lineColor=[UIColor greenColor];
                                        InterfaceLine * interfaceLine=[[[InterfaceLine alloc] initWithBeginPoint:lineBeginPoint endPoint:lineEndPoint color:lineColor] autorelease];
                                        
                                        CGContextSetLineWidth(context, 2.0);
                                        CGContextSetStrokeColor(context, CGColorGetComponents(lineColor.CGColor));
                                        CGContextBeginPath(context);
                                        //                                CGContextMoveToPoint(context, rightPoint.X, rightPoint.Y+nextLabel.frame.origin.y);
                                        CGContextMoveToPoint(context, interfaceLine.beginPoint.X, interfaceLine.beginPoint.Y);
                                        //                                CGContextAddLineToPoint(context, rightPoint.X-[bLink getOffsetX], rightPoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y);
                                        CGContextAddLineToPoint(context, interfaceLine.endPoint.X, interfaceLine.endPoint.Y);
                                        
                                        CGContextStrokePath(context);
                                        [self.bandLineBeginList addObject:interfaceLine];
                                        
                                        
                                        
                                        
                                        InterfacePoint *lineBeginPoint2=[[[InterfacePoint alloc] initWithXY:bandLeftBeginPoint.X Y:bandLeftBeginPoint.Y]autorelease];
                                        InterfacePoint *lineEndPoint2=[[[InterfacePoint alloc] initWithXY:bandLeftEndPoint.X Y:bandLeftEndPoint.Y]autorelease];;
                                        const float* colors = CGColorGetComponents(lineColor.CGColor);
                                        UIColor *squareColor=[UIColor colorWithRed:colors[0] green:colors[1] blue:colors[2] alpha:0.5];
                                        
                                        CGContextSetRGBFillColor(context, colors[0], colors[1],colors[2], 0.5);
                                        InterfaceSquareArea *square=[[InterfaceSquareArea alloc] initWithTopLeftPoint:lineBeginPoint2 topRightPoint:lineEndPoint bottomLeftPoint:lineEndPoint2 bottomRightPoint:lineBeginPoint color:squareColor];
                                        CGContextBeginPath(context);
                                        CGContextMoveToPoint   (context, square.topLeftPoint.X, square.topLeftPoint.Y);
                                        CGContextAddLineToPoint(context, square.topRightPoint.X, square.topRightPoint.Y);
                                        CGContextAddLineToPoint(context, square.bottomRightPoint.X, square.bottomRightPoint.Y);
                                        CGContextAddLineToPoint(context, square.bottomLeftPoint.X, square.bottomLeftPoint.Y);
                                        CGContextClosePath(context);
                                        
                                        CGContextFillPath(context);
                                        [self.squareAreaList addObject:square];
                                        bandWasIntterupted=YES;

                                        //                                [self.bandLineBeginList addObject:[[[InterfacePoint alloc] initWithXY:rightPoint.X Y:rightPoint.Y+nextLabel.frame.origin.y] autorelease]];
                                        //
                                        //                                [self.bandLineEndList addObject:[[[InterfacePoint alloc] initWithXY:rightPoint.X-[bLink getOffsetX] Y:rightPoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y] autorelease]];
                                        //                                [self.bandLineColorList addObject:[UIColor redColor]];
                                        
                                    }
                                    
                                    
                                }
                            }
                            
                            InterfacePoint *lineBeginPoint=[[[InterfacePoint alloc] initWithXY:bandLeftBeginPoint.X Y:bandLeftBeginPoint.Y]autorelease];
                            InterfacePoint *lineEndPoint=[[[InterfacePoint alloc] initWithXY:bandLeftEndPoint.X Y:bandLeftEndPoint.Y]autorelease];;
                            UIColor *lineColor=[UIColor greenColor];
                            InterfaceLine * interfaceLine=[[[InterfaceLine alloc] initWithBeginPoint:lineBeginPoint endPoint:lineEndPoint color:lineColor] autorelease];
                            
                            CGContextSetLineWidth(context, 2.0);
                            CGContextSetStrokeColor(context, CGColorGetComponents(lineColor.CGColor));
                            CGContextBeginPath(context);
                            //                    CGContextMoveToPoint(context, bandLeftBeginPoint.X, bandLeftBeginPoint.Y);
                            CGContextMoveToPoint(context, interfaceLine.beginPoint.X, interfaceLine.beginPoint.Y);
                            
                            //                    CGContextAddLineToPoint(context, bandLeftEndPoint.X,bandLeftEndPoint.Y);
                            CGContextAddLineToPoint(context, interfaceLine.endPoint.X,interfaceLine.endPoint.Y);
                            CGContextStrokePath(context);
                            
                            [self.bandLineBeginList addObject:interfaceLine];
                            NSLog(@"\\nbeginPointX=%f,beginPointY=%f,endPointX=%f,endPointY=%f",interfaceLine.beginPoint.X,interfaceLine.beginPoint.Y,interfaceLine.endPoint.X,interfaceLine.endPoint.Y);
                            
                            //                    [self.bandLineEndList addObject:[[[InterfacePoint alloc] initWithXY:bandLeftEndPoint.X Y:bandLeftEndPoint.Y] autorelease]];
                            
                            //                    [self.bandLineColorList addObject:[UIColor greenColor]];
                            
                            
                            
                            
                            InterfacePoint *lineBeginPoint2=[[[InterfacePoint alloc] initWithXY:bandRightBeginPoint.X Y:bandRightBeginPoint.Y]autorelease];
                            InterfacePoint *lineEndPoint2=[[[InterfacePoint alloc] initWithXY:bandRightEndPoint.X Y:bandRightEndPoint.Y]autorelease];;
//                            UIColor *lineColor2=[UIColor redColor];
                            UIColor *lineColor2=[UIColor greenColor];
                            InterfaceLine * line2=[[[InterfaceLine alloc] initWithBeginPoint:lineBeginPoint2 endPoint:lineEndPoint2 color:lineColor2] autorelease];
                            CGContextSetLineWidth(context, 2.0);
                            CGContextSetStrokeColor(context, CGColorGetComponents(lineColor2.CGColor));
                            CGContextBeginPath(context);
                            //                    CGContextMoveToPoint(context, bandRightBeginPoint.X, bandRightBeginPoint.Y);
                            CGContextMoveToPoint(context, line2.beginPoint.X, line2.beginPoint.Y);
                            //                    CGContextAddLineToPoint(context, bandRightEndPoint.X,bandRightEndPoint.Y);
                            CGContextAddLineToPoint(context, line2.endPoint.X,line2.endPoint.Y);
                            CGContextStrokePath(context);
                            [self.bandLineBeginList addObject:line2];
                            NSLog(@"\\nbeginPointX=%f,beginPointY=%f,endPointX=%f,endPointY=%f",line2.beginPoint.X,line2.beginPoint.Y,line2.endPoint.X,line2.endPoint.Y);
                            
                            //                    [self.bandLineEndList addObject:[[[InterfacePoint alloc] initWithXY:bandRightEndPoint.X Y:bandRightEndPoint.Y] autorelease]];
                            
                            //                    [self.bandLineColorList addObject:[UIColor redColor]];
                            if (!bandWasIntterupted) {
                                const float* colors = CGColorGetComponents(lineColor2.CGColor);
                                UIColor *squareColor=[UIColor colorWithRed:colors[0] green:colors[1] blue:colors[2] alpha:0.5];
                                
                                CGContextSetRGBFillColor(context, colors[0], colors[1],colors[2], 0.5);
                                InterfaceSquareArea *square=[[InterfaceSquareArea alloc] initWithTopLeftPoint:lineBeginPoint topRightPoint:lineBeginPoint2 bottomLeftPoint:lineEndPoint bottomRightPoint:lineEndPoint2 color:squareColor];
                                CGContextBeginPath(context);
                                CGContextMoveToPoint   (context, square.topLeftPoint.X, square.topLeftPoint.Y);
                                CGContextAddLineToPoint(context, square.topRightPoint.X, square.topRightPoint.Y);
                                CGContextAddLineToPoint(context, square.bottomRightPoint.X, square.bottomRightPoint.Y);
                                CGContextAddLineToPoint(context, square.bottomLeftPoint.X, square.bottomLeftPoint.Y);
                                CGContextClosePath(context);
                                
                                CGContextFillPath(context);
                                [self.squareAreaList addObject:square];
                            }
                        }
                        
                        
                    }
                }
                if (beforeLink) {
                    
                    
                    for (int k=0;k< label.sbandLeftEndPoints.count;k++) {
                        {
                            InterfacePoint *point =[label.sbandLeftEndPoints objectAtIndex:k];
                            InterfacePoint *endPoint=[label.sbandRightEndPoints objectAtIndex:k];
                            
                            Link *beforeLink=label.beforeLink;
                            if (!beforeLink) {
                                continue;
                            }
                            
                            InterfacePoint *tempBandLeftBeginPoint=[[[InterfacePoint alloc] initWithXY:0 Y:0] autorelease];
                            InterfacePoint *tempBandLeftEndPoint=[[[InterfacePoint alloc] initWithXY:0 Y:0] autorelease];
                            InterfacePoint *tempBandRightBeginPoint=[[[InterfacePoint alloc] initWithXY:0 Y:0] autorelease];
                            InterfacePoint *tempBandRightEndPoint=[[[InterfacePoint alloc] initWithXY:0 Y:0] autorelease];
                            
                            {
                                tempBandLeftBeginPoint.X=point.X;
                                tempBandLeftBeginPoint.Y=point.Y+label.frame.origin.y;
                                tempBandLeftEndPoint.X=point.X-[beforeLink getOffsetX]*timeToPixel;
                                tempBandLeftEndPoint.Y=point.Y-[beforeLink getOffsetY]+label.frame.origin.y;
                                
                                tempBandRightBeginPoint.X=endPoint.X;
                                tempBandRightBeginPoint.Y=endPoint.Y+label.frame.origin.y;
                                tempBandRightEndPoint.X=endPoint.X-[beforeLink getOffsetX]*timeToPixel;
                                tempBandRightEndPoint.Y=endPoint.Y-[beforeLink getOffsetY]+label.frame.origin.y;
                                
                                UIColor *lineColor=[UIColor greenColor];
                                InterfaceLine * interfaceLine=[[[InterfaceLine alloc] initWithBeginPoint:tempBandLeftBeginPoint endPoint:tempBandLeftEndPoint color:lineColor] autorelease];
                                CGContextSetLineWidth(context, 2.0);
                                CGContextSetStrokeColor(context, CGColorGetComponents(lineColor.CGColor));
                                CGContextBeginPath(context);
                                //                                CGContextMoveToPoint(context, leftpoint.X, leftpoint.Y+nextLabel.frame.origin.y);
                                CGFloat dashArray[] = {2,6,4,2};
                                
                                CGContextSetLineDash(context, 3, dashArray, 4);
                                interfaceLine.dashed=YES;
                                CGContextMoveToPoint(context, interfaceLine.beginPoint.X,interfaceLine.beginPoint.Y);
                                //                                CGContextAddLineToPoint(context, leftpoint.X-[bLink getOffsetX], leftpoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y);
                                CGContextAddLineToPoint(context, interfaceLine.endPoint.X, interfaceLine.endPoint.Y);
                                CGContextStrokePath(context);
                                [self.bandLineBeginList addObject:interfaceLine];
                                CGContextSetLineDash(context, 0, nil, 0);
                            }
                            {
                                tempBandLeftBeginPoint.X=point.X;
                                tempBandLeftBeginPoint.Y=point.Y+label.frame.origin.y;
                                tempBandLeftEndPoint.X=point.X-[beforeLink getOffsetX]*timeToPixel;
                                tempBandLeftEndPoint.Y=point.Y-[beforeLink getOffsetY]+label.frame.origin.y;
                                
                                tempBandRightBeginPoint.X=endPoint.X;
                                tempBandRightBeginPoint.Y=endPoint.Y+label.frame.origin.y;
                                tempBandRightEndPoint.X=endPoint.X-[beforeLink getOffsetX]*timeToPixel;
                                tempBandRightEndPoint.Y=endPoint.Y-[beforeLink getOffsetY]+label.frame.origin.y;
                                
                                UIColor *lineColor=[UIColor greenColor];
                                InterfaceLine * interfaceLine=[[[InterfaceLine alloc] initWithBeginPoint:tempBandRightBeginPoint endPoint:tempBandRightEndPoint color:lineColor] autorelease];
                                CGContextSetLineWidth(context, 2.0);
                                CGContextSetStrokeColor(context, CGColorGetComponents(lineColor.CGColor));
                                CGContextBeginPath(context);
                                //                                CGContextMoveToPoint(context, leftpoint.X, leftpoint.Y+nextLabel.frame.origin.y);
                                CGFloat dashArray[] = {2,6,4,2};
                                
                                CGContextSetLineDash(context, 3, dashArray, 4);
                                interfaceLine.dashed=YES;
                                CGContextMoveToPoint(context, interfaceLine.beginPoint.X,interfaceLine.beginPoint.Y);
                                //                                CGContextAddLineToPoint(context, leftpoint.X-[bLink getOffsetX], leftpoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y);
                                CGContextAddLineToPoint(context, interfaceLine.endPoint.X, interfaceLine.endPoint.Y);
                                CGContextStrokePath(context);
                                [self.bandLineBeginList addObject:interfaceLine];
                                CGContextSetLineDash(context, 0, nil, 0);
                            }
                        }
                    }
                }

            }
                
                break;
            case EASTBOUND:
            case WESTBOUND:
            {
                Link *afterLink=label.afterLink;
                Link *beforeLink=label.beforeLink;
                if (afterLink) {
                    DynamicSignalLabel *nextLabel=[self.dynamicSignalLabelList objectAtIndex:i+1];
                    
                    for (int k=0;k< label.ebandLeftBeginPoints.count;k++) {
                        InterfacePoint *point =[label.ebandLeftBeginPoints objectAtIndex:k];
                        InterfacePoint *endPoint=[label.ebandrightBeginPoints objectAtIndex:k];
                        
                        bandLeftBeginPoint.X=point.X;
                        bandLeftBeginPoint.Y=point.Y+label.frame.origin.y;
                        bandLeftEndPoint.X=point.X+[afterLink getOffsetX]*timeToPixel;
                        bandLeftEndPoint.Y=point.Y+[afterLink getOffsetY]+label.frame.origin.y;
                        
                        bandRightBeginPoint.X=endPoint.X;
                        bandRightBeginPoint.Y=endPoint.Y+label.frame.origin.y;
                        bandRightEndPoint.X=endPoint.X+[afterLink getOffsetX]*timeToPixel;
                        bandRightEndPoint.Y=endPoint.Y+[afterLink getOffsetY]+label.frame.origin.y;
                        //                BOOL leftArriveAtGreen=NO;
                        
                        {
                            int j=0;
                            if (nextLabel.ebandLeftEndPoints.count>0)
                            {
                                InterfacePoint *rightPoint=[nextLabel.ebandLeftEndPoints objectAtIndex:j];
                                InterfacePoint *leftPoint=[[[InterfacePoint alloc] initWithXY:nextLabel.frame.origin.x Y:nextLabel.frame.origin.y] autorelease];
                                
                                if (bandLeftEndPoint.X>leftPoint.X && bandLeftEndPoint.X<rightPoint.X) {
                                    bandLeftBeginPoint.X=bandLeftBeginPoint.X+(rightPoint.X- bandLeftEndPoint.X);
                                    bandLeftEndPoint.X=bandLeftEndPoint.X+(rightPoint.X- bandLeftEndPoint.X);
                                    //                        break;
                                }
                            }else
                            {
                                break;
                            }
                            //                    if (bandRightEndPoint.X>leftPoint.X && bandRightEndPoint.X<rightPoint.X) {
                            //                        bandRightBeginPoint.X=bandRightBeginPoint.X-(bandRightEndPoint.X-leftPoint.X);
                            //                        bandRightEndPoint.X=bandRightEndPoint.X-(bandRightEndPoint.X-leftPoint.X);
                            //                        //                        break;
                            //                    }
                        }
                        for (int j=1; j<nextLabel.ebandLeftEndPoints.count; j++) {
                            InterfacePoint *rightPoint=[nextLabel.ebandLeftEndPoints objectAtIndex:j];
                            InterfacePoint *leftPoint=[nextLabel.ebandRightEndPoints objectAtIndex:j-1];
                            
                            if (bandLeftEndPoint.X>leftPoint.X && bandLeftEndPoint.X<rightPoint.X) {
                                bandLeftBeginPoint.X=bandLeftBeginPoint.X+(rightPoint.X- bandLeftEndPoint.X);
                                bandLeftEndPoint.X=bandLeftEndPoint.X+(rightPoint.X- bandLeftEndPoint.X);
                                //                        break;
                            }
                            if (bandRightEndPoint.X>leftPoint.X && bandRightEndPoint.X<rightPoint.X) {
                                bandRightBeginPoint.X=bandRightBeginPoint.X-(bandRightEndPoint.X-leftPoint.X);
                                bandRightEndPoint.X=bandRightEndPoint.X-(bandRightEndPoint.X-leftPoint.X);
                                //                        break;
                            }
                            
                        }
                        {
                            int j=nextLabel.ebandLeftEndPoints.count-1;
                            InterfacePoint *rightPoint=[[[InterfacePoint alloc] initWithXY:nextLabel.frame.origin.x+nextLabel.frame.size.width Y:nextLabel.frame.origin.y] autorelease];
                            if (nextLabel.ebandRightEndPoints.count>0) {
                                InterfacePoint *leftPoint=[nextLabel.ebandRightEndPoints objectAtIndex:j];
                                
                                //                    if (bandLeftEndPoint.X>leftPoint.X && bandLeftEndPoint.X<rightPoint.X) {
                                //                        bandLeftBeginPoint.X=bandLeftBeginPoint.X+(rightPoint.X- bandLeftEndPoint.X);
                                //                        bandLeftEndPoint.X=bandLeftEndPoint.X+(rightPoint.X- bandLeftEndPoint.X);
                                //                        //                        break;
                                //                    }
                                if (bandRightEndPoint.X>leftPoint.X && bandRightEndPoint.X<rightPoint.X) {
                                    bandRightBeginPoint.X=bandRightBeginPoint.X-(bandRightEndPoint.X-leftPoint.X);
                                    bandRightEndPoint.X=bandRightEndPoint.X-(bandRightEndPoint.X-leftPoint.X);
                                    //                        break;
                                }
                            }else
                            {
                                break;
                            }
                        }
                        //                for (int j=1; j<nextLabel.bandLeftEndPoints.count; j++) {
                        //                    InterfacePoint *rightPoint=[nextLabel.bandLeftEndPoints objectAtIndex:j];
                        //                    InterfacePoint *leftPoint=[nextLabel.bandRightEndPoints objectAtIndex:j-1];
                        //
                        //
                        //                }
                        
                        //eastbound
                        if (bandLeftBeginPoint.X<=bandRightBeginPoint.X) {
                            
                            Link *bLink=nextLabel.beforeLink;
                            BOOL bandWasIntterupted=NO;
                            //                    Link *aLink=nextLabel.afterLink;
                            if (bLink) {
                                for (int m=0;m<nextLabel.ebandLeftEndPoints.count;m++) {
                                    InterfacePoint *leftpoint=[nextLabel.ebandLeftEndPoints objectAtIndex:m];
                                    InterfacePoint *rightPoint=[nextLabel.ebandRightEndPoints objectAtIndex:m];
                                    if (leftpoint.X>bandLeftEndPoint.X &&leftpoint.X<bandRightEndPoint.X) {
                                        InterfacePoint *lineBeginPoint=[[[InterfacePoint alloc] initWithXY:leftpoint.X Y:leftpoint.Y+nextLabel.frame.origin.y] autorelease];
                                        InterfacePoint *lineEndPoint=[[[InterfacePoint alloc] initWithXY:leftpoint.X-[bLink getOffsetX]*timeToPixel Y:leftpoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y] autorelease];
                                        UIColor *lineColor=[UIColor greenColor];
                                        InterfaceLine * interfaceLine=[[[InterfaceLine alloc] initWithBeginPoint:lineBeginPoint endPoint:lineEndPoint color:lineColor] autorelease];
                                        CGContextSetLineWidth(context, 2.0);
                                        CGContextSetStrokeColor(context, CGColorGetComponents(lineColor.CGColor));
                                        CGContextBeginPath(context);
                                        //                                CGContextMoveToPoint(context, leftpoint.X, leftpoint.Y+nextLabel.frame.origin.y);
                                        CGContextMoveToPoint(context, interfaceLine.beginPoint.X,interfaceLine.beginPoint.Y);
                                        //                                CGContextAddLineToPoint(context, leftpoint.X-[bLink getOffsetX], leftpoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y);
                                        CGContextAddLineToPoint(context, interfaceLine.endPoint.X, interfaceLine.endPoint.Y);
                                        CGContextStrokePath(context);
                                        [self.bandLineBeginList addObject:interfaceLine];
                                        
                                        
                                        
                                        
                                        InterfacePoint *lineBeginPoint2=[[[InterfacePoint alloc] initWithXY:bandRightBeginPoint.X Y:bandRightBeginPoint.Y]autorelease];
                                        InterfacePoint *lineEndPoint2=[[[InterfacePoint alloc] initWithXY:bandRightEndPoint.X Y:bandRightEndPoint.Y]autorelease];;
                                        const float* colors = CGColorGetComponents(lineColor.CGColor);
                                        UIColor *squareColor=[UIColor colorWithRed:colors[0] green:colors[1] blue:colors[2] alpha:0.5];
                                        
                                        CGContextSetRGBFillColor(context, colors[0], colors[1],colors[2], 0.5);
                                        InterfaceSquareArea *square=[[InterfaceSquareArea alloc] initWithTopLeftPoint:lineEndPoint topRightPoint:lineBeginPoint2 bottomLeftPoint:lineBeginPoint bottomRightPoint:lineEndPoint2 color:squareColor];
                                        CGContextBeginPath(context);
                                        CGContextMoveToPoint   (context, square.topLeftPoint.X, square.topLeftPoint.Y);
                                        CGContextAddLineToPoint(context, square.topRightPoint.X, square.topRightPoint.Y);
                                        CGContextAddLineToPoint(context, square.bottomRightPoint.X, square.bottomRightPoint.Y);
                                        CGContextAddLineToPoint(context, square.bottomLeftPoint.X, square.bottomLeftPoint.Y);
                                        CGContextClosePath(context);
                                        
                                        CGContextFillPath(context);
                                        [self.squareAreaList addObject:square];
                                        bandWasIntterupted=YES;
                                        //                                [self.bandLineEndList addObject:[[[InterfacePoint alloc] initWithXY:leftpoint.X-[bLink getOffsetX] Y:leftpoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y] autorelease]];
                                        //                                [self.bandLineColorList addObject:[UIColor greenColor]];
                                        
                                    }
                                    if (rightPoint.X>bandLeftEndPoint.X &&rightPoint.X<bandRightEndPoint.X) {
                                        
                                        InterfacePoint *lineBeginPoint=[[[InterfacePoint alloc] initWithXY:rightPoint.X Y:rightPoint.Y+nextLabel.frame.origin.y] autorelease];
                                        InterfacePoint *lineEndPoint=[[[InterfacePoint alloc] initWithXY:rightPoint.X-[bLink getOffsetX]*timeToPixel Y:rightPoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y] autorelease];
//                                        UIColor *lineColor=[UIColor redColor];
                                        UIColor *lineColor=[UIColor greenColor];
                                        InterfaceLine * interfaceLine=[[[InterfaceLine alloc] initWithBeginPoint:lineBeginPoint endPoint:lineEndPoint color:lineColor] autorelease];
                                        
                                        CGContextSetLineWidth(context, 2.0);
                                        CGContextSetStrokeColor(context, CGColorGetComponents(lineColor.CGColor));
                                        CGContextBeginPath(context);
                                        //                                CGContextMoveToPoint(context, rightPoint.X, rightPoint.Y+nextLabel.frame.origin.y);
                                        CGContextMoveToPoint(context, interfaceLine.beginPoint.X, interfaceLine.beginPoint.Y);
                                        //                                CGContextAddLineToPoint(context, rightPoint.X-[bLink getOffsetX], rightPoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y);
                                        CGContextAddLineToPoint(context, interfaceLine.endPoint.X, interfaceLine.endPoint.Y);
                                        
                                        CGContextStrokePath(context);
                                        [self.bandLineBeginList addObject:interfaceLine];
                                        
                                        
                                        
                                        
                                        InterfacePoint *lineBeginPoint2=[[[InterfacePoint alloc] initWithXY:bandLeftBeginPoint.X Y:bandLeftBeginPoint.Y]autorelease];
                                        InterfacePoint *lineEndPoint2=[[[InterfacePoint alloc] initWithXY:bandLeftEndPoint.X Y:bandLeftEndPoint.Y]autorelease];;
                                        const float* colors = CGColorGetComponents(lineColor.CGColor);
                                        UIColor *squareColor=[UIColor colorWithRed:colors[0] green:colors[1] blue:colors[2] alpha:0.5];
                                        
                                        CGContextSetRGBFillColor(context, colors[0], colors[1],colors[2], 0.5);
                                        InterfaceSquareArea *square=[[InterfaceSquareArea alloc] initWithTopLeftPoint:lineBeginPoint2 topRightPoint:lineEndPoint bottomLeftPoint:lineEndPoint2 bottomRightPoint:lineBeginPoint color:squareColor];
                                        CGContextBeginPath(context);
                                        CGContextMoveToPoint   (context, square.topLeftPoint.X, square.topLeftPoint.Y);
                                        CGContextAddLineToPoint(context, square.topRightPoint.X, square.topRightPoint.Y);
                                        CGContextAddLineToPoint(context, square.bottomRightPoint.X, square.bottomRightPoint.Y);
                                        CGContextAddLineToPoint(context, square.bottomLeftPoint.X, square.bottomLeftPoint.Y);
                                        CGContextClosePath(context);
                                        
                                        CGContextFillPath(context);
                                        [self.squareAreaList addObject:square];
                                        bandWasIntterupted=YES;

                                        //                                [self.bandLineBeginList addObject:[[[InterfacePoint alloc] initWithXY:rightPoint.X Y:rightPoint.Y+nextLabel.frame.origin.y] autorelease]];
                                        //
                                        //                                [self.bandLineEndList addObject:[[[InterfacePoint alloc] initWithXY:rightPoint.X-[bLink getOffsetX] Y:rightPoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y] autorelease]];
                                        //                                [self.bandLineColorList addObject:[UIColor redColor]];
                                        
                                    }
                                    
                                    
                                }
                            }
                            
                            InterfacePoint *lineBeginPoint=[[[InterfacePoint alloc] initWithXY:bandLeftBeginPoint.X Y:bandLeftBeginPoint.Y]autorelease];
                            InterfacePoint *lineEndPoint=[[[InterfacePoint alloc] initWithXY:bandLeftEndPoint.X Y:bandLeftEndPoint.Y]autorelease];;
                            UIColor *lineColor=[UIColor greenColor];
                            InterfaceLine * interfaceLine=[[[InterfaceLine alloc] initWithBeginPoint:lineBeginPoint endPoint:lineEndPoint color:lineColor] autorelease];
                            
                            CGContextSetLineWidth(context, 2.0);
                            CGContextSetStrokeColor(context, CGColorGetComponents(lineColor.CGColor));
                            CGContextBeginPath(context);
                            //                    CGContextMoveToPoint(context, bandLeftBeginPoint.X, bandLeftBeginPoint.Y);
                            CGContextMoveToPoint(context, interfaceLine.beginPoint.X, interfaceLine.beginPoint.Y);
                            
                            //                    CGContextAddLineToPoint(context, bandLeftEndPoint.X,bandLeftEndPoint.Y);
                            CGContextAddLineToPoint(context, interfaceLine.endPoint.X,interfaceLine.endPoint.Y);
                            CGContextStrokePath(context);
                            
                            [self.bandLineBeginList addObject:interfaceLine];
                            NSLog(@"\\nbeginPointX=%f,beginPointY=%f,endPointX=%f,endPointY=%f",interfaceLine.beginPoint.X,interfaceLine.beginPoint.Y,interfaceLine.endPoint.X,interfaceLine.endPoint.Y);
                            
                            //                    [self.bandLineEndList addObject:[[[InterfacePoint alloc] initWithXY:bandLeftEndPoint.X Y:bandLeftEndPoint.Y] autorelease]];
                            
                            //                    [self.bandLineColorList addObject:[UIColor greenColor]];
                            
                            
                            
                            
                            InterfacePoint *lineBeginPoint2=[[[InterfacePoint alloc] initWithXY:bandRightBeginPoint.X Y:bandRightBeginPoint.Y]autorelease];
                            InterfacePoint *lineEndPoint2=[[[InterfacePoint alloc] initWithXY:bandRightEndPoint.X Y:bandRightEndPoint.Y]autorelease];;
//                            UIColor *lineColor2=[UIColor redColor];
                            UIColor *lineColor2=[UIColor greenColor];
                            InterfaceLine * line2=[[[InterfaceLine alloc] initWithBeginPoint:lineBeginPoint2 endPoint:lineEndPoint2 color:lineColor2] autorelease];
                            CGContextSetLineWidth(context, 2.0);
                            CGContextSetStrokeColor(context, CGColorGetComponents(lineColor2.CGColor));
                            CGContextBeginPath(context);
                            //                    CGContextMoveToPoint(context, bandRightBeginPoint.X, bandRightBeginPoint.Y);
                            CGContextMoveToPoint(context, line2.beginPoint.X, line2.beginPoint.Y);
                            //                    CGContextAddLineToPoint(context, bandRightEndPoint.X,bandRightEndPoint.Y);
                            CGContextAddLineToPoint(context, line2.endPoint.X,line2.endPoint.Y);
                            CGContextStrokePath(context);
                            [self.bandLineBeginList addObject:line2];
                            NSLog(@"\\nbeginPointX=%f,beginPointY=%f,endPointX=%f,endPointY=%f",line2.beginPoint.X,line2.beginPoint.Y,line2.endPoint.X,line2.endPoint.Y);
                            
                            //                    [self.bandLineEndList addObject:[[[InterfacePoint alloc] initWithXY:bandRightEndPoint.X Y:bandRightEndPoint.Y] autorelease]];
                            
                            //                    [self.bandLineColorList addObject:[UIColor redColor]];
                            if (!bandWasIntterupted) {
                                const float* colors = CGColorGetComponents(lineColor2.CGColor);
                                UIColor *squareColor=[UIColor colorWithRed:colors[0] green:colors[1] blue:colors[2] alpha:0.5];
                                
                                CGContextSetRGBFillColor(context, colors[0], colors[1],colors[2], 0.5);
                                InterfaceSquareArea *square=[[InterfaceSquareArea alloc] initWithTopLeftPoint:lineBeginPoint topRightPoint:lineBeginPoint2 bottomLeftPoint:lineEndPoint bottomRightPoint:lineEndPoint2 color:squareColor];
                                CGContextBeginPath(context);
                                CGContextMoveToPoint   (context, square.topLeftPoint.X, square.topLeftPoint.Y);
                                CGContextAddLineToPoint(context, square.topRightPoint.X, square.topRightPoint.Y);
                                CGContextAddLineToPoint(context, square.bottomRightPoint.X, square.bottomRightPoint.Y);
                                CGContextAddLineToPoint(context, square.bottomLeftPoint.X, square.bottomLeftPoint.Y);
                                CGContextClosePath(context);
                                
                                CGContextFillPath(context);
                                [self.squareAreaList addObject:square];
                            }
                        }
                        
                        
                    }
                }
                if (beforeLink) {
                    
                    
                    for (int k=0;k< label.ebandLeftEndPoints.count;k++) {
                        {
                            InterfacePoint *point =[label.ebandLeftEndPoints objectAtIndex:k];
                            InterfacePoint *endPoint=[label.ebandRightEndPoints objectAtIndex:k];
                            
                            Link *beforeLink=label.beforeLink;
                            if (!beforeLink) {
                                continue;
                            }
                            
                            InterfacePoint *tempBandLeftBeginPoint=[[[InterfacePoint alloc] initWithXY:0 Y:0] autorelease];
                            InterfacePoint *tempBandLeftEndPoint=[[[InterfacePoint alloc] initWithXY:0 Y:0] autorelease];
                            InterfacePoint *tempBandRightBeginPoint=[[[InterfacePoint alloc] initWithXY:0 Y:0] autorelease];
                            InterfacePoint *tempBandRightEndPoint=[[[InterfacePoint alloc] initWithXY:0 Y:0] autorelease];
                            
                            {
                                tempBandLeftBeginPoint.X=point.X;
                                tempBandLeftBeginPoint.Y=point.Y+label.frame.origin.y;
                                tempBandLeftEndPoint.X=point.X-[beforeLink getOffsetX]*timeToPixel;
                                tempBandLeftEndPoint.Y=point.Y-[beforeLink getOffsetY]+label.frame.origin.y;
                                
                                tempBandRightBeginPoint.X=endPoint.X;
                                tempBandRightBeginPoint.Y=endPoint.Y+label.frame.origin.y;
                                tempBandRightEndPoint.X=endPoint.X-[beforeLink getOffsetX]*timeToPixel;
                                tempBandRightEndPoint.Y=endPoint.Y-[beforeLink getOffsetY]+label.frame.origin.y;
                                
                                UIColor *lineColor=[UIColor greenColor];
                                InterfaceLine * interfaceLine=[[[InterfaceLine alloc] initWithBeginPoint:tempBandLeftBeginPoint endPoint:tempBandLeftEndPoint color:lineColor] autorelease];
                                CGContextSetLineWidth(context, 2.0);
                                CGContextSetStrokeColor(context, CGColorGetComponents(lineColor.CGColor));
                                CGContextBeginPath(context);
                                //                                CGContextMoveToPoint(context, leftpoint.X, leftpoint.Y+nextLabel.frame.origin.y);
                                CGFloat dashArray[] = {2,6,4,2};
                                
                                CGContextSetLineDash(context, 3, dashArray, 4);
                                interfaceLine.dashed=YES;
                                CGContextMoveToPoint(context, interfaceLine.beginPoint.X,interfaceLine.beginPoint.Y);
                                //                                CGContextAddLineToPoint(context, leftpoint.X-[bLink getOffsetX], leftpoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y);
                                CGContextAddLineToPoint(context, interfaceLine.endPoint.X, interfaceLine.endPoint.Y);
                                CGContextStrokePath(context);
                                [self.bandLineBeginList addObject:interfaceLine];
                                CGContextSetLineDash(context, 0, nil, 0);
                            }
                            {
                                tempBandLeftBeginPoint.X=point.X;
                                tempBandLeftBeginPoint.Y=point.Y+label.frame.origin.y;
                                tempBandLeftEndPoint.X=point.X-[beforeLink getOffsetX]*timeToPixel;
                                tempBandLeftEndPoint.Y=point.Y-[beforeLink getOffsetY]+label.frame.origin.y;
                                
                                tempBandRightBeginPoint.X=endPoint.X;
                                tempBandRightBeginPoint.Y=endPoint.Y+label.frame.origin.y;
                                tempBandRightEndPoint.X=endPoint.X-[beforeLink getOffsetX]*timeToPixel;
                                tempBandRightEndPoint.Y=endPoint.Y-[beforeLink getOffsetY]+label.frame.origin.y;
                                
                                UIColor *lineColor=[UIColor greenColor];
                                InterfaceLine * interfaceLine=[[[InterfaceLine alloc] initWithBeginPoint:tempBandRightBeginPoint endPoint:tempBandRightEndPoint color:lineColor] autorelease];
                                CGContextSetLineWidth(context, 2.0);
                                CGContextSetStrokeColor(context, CGColorGetComponents(lineColor.CGColor));
                                CGContextBeginPath(context);
                                //                                CGContextMoveToPoint(context, leftpoint.X, leftpoint.Y+nextLabel.frame.origin.y);
                                CGFloat dashArray[] = {2,6,4,2};
                                
                                CGContextSetLineDash(context, 3, dashArray, 4);
                                interfaceLine.dashed=YES;
                                CGContextMoveToPoint(context, interfaceLine.beginPoint.X,interfaceLine.beginPoint.Y);
                                //                                CGContextAddLineToPoint(context, leftpoint.X-[bLink getOffsetX], leftpoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y);
                                CGContextAddLineToPoint(context, interfaceLine.endPoint.X, interfaceLine.endPoint.Y);
                                CGContextStrokePath(context);
                                [self.bandLineBeginList addObject:interfaceLine];
                                CGContextSetLineDash(context, 0, nil, 0);
                            }
                        }
                    }
                }

            }
                
            {
                Link *beforeLink=label.beforeLink;
                Link *afterLink=label.afterLink;
                if (beforeLink) {
                    DynamicSignalLabel *nextLabel=[self.dynamicSignalLabelList objectAtIndex:i-1];
                    
                    for (int k=0;k< label.wbandLeftBeginPoints.count;k++) {
                        InterfacePoint *point =[label.wbandLeftEndPoints objectAtIndex:k];
                        InterfacePoint *endPoint=[label.wbandRightEndPoints objectAtIndex:k];
                        
                        bandLeftBeginPoint.X=point.X;
                        bandLeftBeginPoint.Y=point.Y+label.frame.origin.y;
                        bandLeftEndPoint.X=point.X+[beforeLink getOffsetX]*timeToPixel;
                        bandLeftEndPoint.Y=point.Y-[beforeLink getOffsetY]+label.frame.origin.y;
                        
                        bandRightBeginPoint.X=endPoint.X;
                        bandRightBeginPoint.Y=endPoint.Y+label.frame.origin.y;
                        bandRightEndPoint.X=endPoint.X+[beforeLink getOffsetX]*timeToPixel;
                        bandRightEndPoint.Y=endPoint.Y-[beforeLink getOffsetY]+label.frame.origin.y;
                        //                BOOL leftArriveAtGreen=NO;
                        
                        {
                            int j=0;
                            if (nextLabel.wbandLeftBeginPoints.count>0) {
                                InterfacePoint *rightPoint=[nextLabel.wbandLeftBeginPoints objectAtIndex:j];
                                InterfacePoint *leftPoint=[[[InterfacePoint alloc] initWithXY:nextLabel.frame.origin.x Y:nextLabel.frame.origin.y+nextLabel.frame.size.height] autorelease];
                                //For the situation that the band left end point arrivies the next signal at red.
                                if (bandLeftEndPoint.X>leftPoint.X && bandLeftEndPoint.X<rightPoint.X) {
                                    bandLeftBeginPoint.X=bandLeftBeginPoint.X+(rightPoint.X- bandLeftEndPoint.X);
                                    bandLeftEndPoint.X=bandLeftEndPoint.X+(rightPoint.X- bandLeftEndPoint.X);
                                    //                        break;
                                }
                                
                            }else
                            {
                                break;
                            }
                            //                    if (bandRightEndPoint.X>leftPoint.X && bandRightEndPoint.X<rightPoint.X) {
                            //                        bandRightBeginPoint.X=bandRightBeginPoint.X-(bandRightEndPoint.X-leftPoint.X);
                            //                        bandRightEndPoint.X=bandRightEndPoint.X-(bandRightEndPoint.X-leftPoint.X);
                            //                        //                        break;
                            //                    }
                        }
                        for (int j=1; j<nextLabel.wbandLeftEndPoints.count; j++) {
                            InterfacePoint *rightPoint=[nextLabel.wbandLeftEndPoints objectAtIndex:j];
                            InterfacePoint *leftPoint=[nextLabel.wbandRightEndPoints objectAtIndex:j-1];
                            
                            if (bandLeftEndPoint.X>leftPoint.X && bandLeftEndPoint.X<rightPoint.X) {
                                bandLeftBeginPoint.X=bandLeftBeginPoint.X+(rightPoint.X- bandLeftEndPoint.X);
                                bandLeftEndPoint.X=bandLeftEndPoint.X+(rightPoint.X- bandLeftEndPoint.X);
                                //                        break;
                            }
                            if (bandRightEndPoint.X>leftPoint.X && bandRightEndPoint.X<rightPoint.X) {
                                bandRightBeginPoint.X=bandRightBeginPoint.X-(bandRightEndPoint.X-leftPoint.X);
                                bandRightEndPoint.X=bandRightEndPoint.X-(bandRightEndPoint.X-leftPoint.X);
                                //                        break;
                            }
                            
                        }
                        {
                            int j=nextLabel.wbandLeftEndPoints.count-1;
                            InterfacePoint *rightPoint=[[[InterfacePoint alloc] initWithXY:nextLabel.frame.origin.x+nextLabel.frame.size.width Y:nextLabel.frame.origin.y+nextLabel.frame.size.height] autorelease];
                            if (nextLabel.wbandRightEndPoints.count>0) {
                                InterfacePoint *leftPoint=[nextLabel.wbandRightEndPoints objectAtIndex:j];
                                
                                //                    if (bandLeftEndPoint.X>leftPoint.X && bandLeftEndPoint.X<rightPoint.X) {
                                //                        bandLeftBeginPoint.X=bandLeftBeginPoint.X+(rightPoint.X- bandLeftEndPoint.X);
                                //                        bandLeftEndPoint.X=bandLeftEndPoint.X+(rightPoint.X- bandLeftEndPoint.X);
                                //                        //                        break;
                                //                    }
                                if (bandRightEndPoint.X>leftPoint.X && bandRightEndPoint.X<rightPoint.X) {
                                    bandRightBeginPoint.X=bandRightBeginPoint.X-(bandRightEndPoint.X-leftPoint.X);
                                    bandRightEndPoint.X=bandRightEndPoint.X-(bandRightEndPoint.X-leftPoint.X);
                                    //                        break;
                                }
                            }else
                            {
                                break;
                            }
                        }
                        //                for (int j=1; j<nextLabel.bandLeftEndPoints.count; j++) {
                        //                    InterfacePoint *rightPoint=[nextLabel.bandLeftEndPoints objectAtIndex:j];
                        //                    InterfacePoint *leftPoint=[nextLabel.bandRightEndPoints objectAtIndex:j-1];
                        //
                        //
                        //                }
                        
                        
                        if (bandLeftBeginPoint.X<=bandRightBeginPoint.X) {
                            
                            Link *aLink=nextLabel.afterLink;
                            //                    Link *aLink=nextLabel.afterLink;
                            BOOL bandWasIntterupted=NO;
                            if (aLink) {
                                for (int m=0;m<nextLabel.wbandLeftBeginPoints.count;m++) {
                                    InterfacePoint *leftpoint=[nextLabel.wbandLeftBeginPoints objectAtIndex:m];
                                    InterfacePoint *rightPoint=[nextLabel.wbandrightBeginPoints objectAtIndex:m];
                                    //if the next signal has a red during the band.
                                    if (leftpoint.X>bandLeftEndPoint.X &&leftpoint.X<bandRightEndPoint.X) {
                                        InterfacePoint *lineBeginPoint=[[[InterfacePoint alloc] initWithXY:leftpoint.X Y:leftpoint.Y+nextLabel.frame.origin.y] autorelease];
                                        InterfacePoint *lineEndPoint=[[[InterfacePoint alloc] initWithXY:leftpoint.X-[aLink getOffsetX]*timeToPixel Y:leftpoint.Y+[aLink getOffsetY]+nextLabel.frame.origin.y] autorelease];
                                        UIColor *lineColor=[UIColor blueColor];
                                        InterfaceLine * interfaceLine=[[[InterfaceLine alloc] initWithBeginPoint:lineBeginPoint endPoint:lineEndPoint color:lineColor] autorelease];
                                        CGContextSetLineWidth(context, 2.0);
                                        CGContextSetStrokeColor(context, CGColorGetComponents(lineColor.CGColor));
                                        CGContextBeginPath(context);
                                        //                                CGContextMoveToPoint(context, leftpoint.X, leftpoint.Y+nextLabel.frame.origin.y);
                                        CGContextMoveToPoint(context, interfaceLine.beginPoint.X,interfaceLine.beginPoint.Y);
                                        //                                CGContextAddLineToPoint(context, leftpoint.X-[bLink getOffsetX], leftpoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y);
                                        CGContextAddLineToPoint(context, interfaceLine.endPoint.X, interfaceLine.endPoint.Y);
                                        CGContextStrokePath(context);
                                        [self.bandLineBeginList addObject:interfaceLine];
                                        
                                        
                                        
                                        
                                        InterfacePoint *lineBeginPoint2=[[[InterfacePoint alloc] initWithXY:bandRightBeginPoint.X Y:bandRightBeginPoint.Y]autorelease];
                                        InterfacePoint *lineEndPoint2=[[[InterfacePoint alloc] initWithXY:bandRightEndPoint.X Y:bandRightEndPoint.Y]autorelease];;
                                        const float* colors = CGColorGetComponents(lineColor.CGColor);
                                        UIColor *squareColor=[UIColor colorWithRed:colors[0] green:colors[1] blue:colors[2] alpha:0.5];
                                        
                                        CGContextSetRGBFillColor(context, colors[0], colors[1],colors[2], 0.5);
                                        InterfaceSquareArea *square=[[InterfaceSquareArea alloc] initWithTopLeftPoint:lineEndPoint topRightPoint:lineBeginPoint2 bottomLeftPoint:lineBeginPoint bottomRightPoint:lineEndPoint2 color:squareColor];
                                        CGContextBeginPath(context);
                                        CGContextMoveToPoint   (context, square.topLeftPoint.X, square.topLeftPoint.Y);
                                        CGContextAddLineToPoint(context, square.topRightPoint.X, square.topRightPoint.Y);
                                        CGContextAddLineToPoint(context, square.bottomRightPoint.X, square.bottomRightPoint.Y);
                                        CGContextAddLineToPoint(context, square.bottomLeftPoint.X, square.bottomLeftPoint.Y);
                                        CGContextClosePath(context);
                                        
                                        CGContextFillPath(context);
                                        [self.squareAreaList addObject:square];
                                        bandWasIntterupted=YES;
                                        //                                [self.bandLineEndList addObject:[[[InterfacePoint alloc] initWithXY:leftpoint.X-[bLink getOffsetX] Y:leftpoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y] autorelease]];
                                        //                                [self.bandLineColorList addObject:[UIColor greenColor]];
                                        
                                    }
                                    if (rightPoint.X>bandLeftEndPoint.X &&rightPoint.X<bandRightEndPoint.X) {
                                        
                                        InterfacePoint *lineBeginPoint=[[[InterfacePoint alloc] initWithXY:rightPoint.X Y:rightPoint.Y+nextLabel.frame.origin.y] autorelease];
                                        InterfacePoint *lineEndPoint=[[[InterfacePoint alloc] initWithXY:rightPoint.X-[aLink getOffsetX]*timeToPixel Y:rightPoint.Y+[aLink getOffsetY]+nextLabel.frame.origin.y] autorelease];
//                                        UIColor *lineColor=[UIColor redColor];
                                        UIColor *lineColor=[UIColor blueColor];
                                        InterfaceLine * interfaceLine=[[[InterfaceLine alloc] initWithBeginPoint:lineBeginPoint endPoint:lineEndPoint color:lineColor] autorelease];
                                        
                                        CGContextSetLineWidth(context, 2.0);
                                        CGContextSetStrokeColor(context, CGColorGetComponents(lineColor.CGColor));
                                        CGContextBeginPath(context);
                                        //                                CGContextMoveToPoint(context, rightPoint.X, rightPoint.Y+nextLabel.frame.origin.y);
                                        CGContextMoveToPoint(context, interfaceLine.beginPoint.X, interfaceLine.beginPoint.Y);
                                        //                                CGContextAddLineToPoint(context, rightPoint.X-[bLink getOffsetX], rightPoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y);
                                        CGContextAddLineToPoint(context, interfaceLine.endPoint.X, interfaceLine.endPoint.Y);
                                        
                                        CGContextStrokePath(context);
                                        [self.bandLineBeginList addObject:interfaceLine];
                                        
                                        
                                        
                                        
                                        InterfacePoint *lineBeginPoint2=[[[InterfacePoint alloc] initWithXY:bandLeftBeginPoint.X Y:bandLeftBeginPoint.Y]autorelease];
                                        InterfacePoint *lineEndPoint2=[[[InterfacePoint alloc] initWithXY:bandLeftEndPoint.X Y:bandLeftEndPoint.Y]autorelease];;
                                        const float* colors = CGColorGetComponents(lineColor.CGColor);
                                        UIColor *squareColor=[UIColor colorWithRed:colors[0] green:colors[1] blue:colors[2] alpha:0.5];
                                        
                                        CGContextSetRGBFillColor(context, colors[0], colors[1],colors[2], 0.5);
                                        InterfaceSquareArea *square=[[InterfaceSquareArea alloc] initWithTopLeftPoint:lineBeginPoint2 topRightPoint:lineEndPoint bottomLeftPoint:lineEndPoint2 bottomRightPoint:lineBeginPoint color:squareColor];
                                        CGContextBeginPath(context);
                                        CGContextMoveToPoint   (context, square.topLeftPoint.X, square.topLeftPoint.Y);
                                        CGContextAddLineToPoint(context, square.topRightPoint.X, square.topRightPoint.Y);
                                        CGContextAddLineToPoint(context, square.bottomRightPoint.X, square.bottomRightPoint.Y);
                                        CGContextAddLineToPoint(context, square.bottomLeftPoint.X, square.bottomLeftPoint.Y);
                                        CGContextClosePath(context);
                                        
                                        CGContextFillPath(context);
                                        [self.squareAreaList addObject:square];
                                        bandWasIntterupted=YES;

                                        //                                [self.bandLineBeginList addObject:[[[InterfacePoint alloc] initWithXY:rightPoint.X Y:rightPoint.Y+nextLabel.frame.origin.y] autorelease]];
                                        //
                                        //                                [self.bandLineEndList addObject:[[[InterfacePoint alloc] initWithXY:rightPoint.X-[bLink getOffsetX] Y:rightPoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y] autorelease]];
                                        //                                [self.bandLineColorList addObject:[UIColor redColor]];
                                        
                                    }
                                    
                                    
                                }
                            }
                            
                            InterfacePoint *lineBeginPoint=[[[InterfacePoint alloc] initWithXY:bandLeftBeginPoint.X Y:bandLeftBeginPoint.Y]autorelease];
                            InterfacePoint *lineEndPoint=[[[InterfacePoint alloc] initWithXY:bandLeftEndPoint.X Y:bandLeftEndPoint.Y]autorelease];;
                            UIColor *lineColor=[UIColor blueColor];
                            InterfaceLine * interfaceLine=[[[InterfaceLine alloc] initWithBeginPoint:lineBeginPoint endPoint:lineEndPoint color:lineColor] autorelease];
                            
                            CGContextSetLineWidth(context, 2.0);
                            CGContextSetStrokeColor(context, CGColorGetComponents(lineColor.CGColor));
                            CGContextBeginPath(context);
                            //                    CGContextMoveToPoint(context, bandLeftBeginPoint.X, bandLeftBeginPoint.Y);
                            CGContextMoveToPoint(context, interfaceLine.beginPoint.X, interfaceLine.beginPoint.Y);
                            
                            //                    CGContextAddLineToPoint(context, bandLeftEndPoint.X,bandLeftEndPoint.Y);
                            CGContextAddLineToPoint(context, interfaceLine.endPoint.X,interfaceLine.endPoint.Y);
                            CGContextStrokePath(context);
                            
                            [self.bandLineBeginList addObject:interfaceLine];
                            NSLog(@"\\nbeginPointX=%f,beginPointY=%f,endPointX=%f,endPointY=%f",interfaceLine.beginPoint.X,interfaceLine.beginPoint.Y,interfaceLine.endPoint.X,interfaceLine.endPoint.Y);
                            
                            //                    [self.bandLineEndList addObject:[[[InterfacePoint alloc] initWithXY:bandLeftEndPoint.X Y:bandLeftEndPoint.Y] autorelease]];
                            
                            //                    [self.bandLineColorList addObject:[UIColor greenColor]];
                            
                            
                            
                            
                            InterfacePoint *lineBeginPoint2=[[[InterfacePoint alloc] initWithXY:bandRightBeginPoint.X Y:bandRightBeginPoint.Y]autorelease];
                            InterfacePoint *lineEndPoint2=[[[InterfacePoint alloc] initWithXY:bandRightEndPoint.X Y:bandRightEndPoint.Y]autorelease];;
//                            UIColor *lineColor2=[UIColor redColor];
                            UIColor *lineColor2=[UIColor blueColor];
                            InterfaceLine * line2=[[[InterfaceLine alloc] initWithBeginPoint:lineBeginPoint2 endPoint:lineEndPoint2 color:lineColor2] autorelease];
                            CGContextSetLineWidth(context, 2.0);
                            CGContextSetStrokeColor(context, CGColorGetComponents(lineColor2.CGColor));
                            CGContextBeginPath(context);
                            //                    CGContextMoveToPoint(context, bandRightBeginPoint.X, bandRightBeginPoint.Y);
                            CGContextMoveToPoint(context, line2.beginPoint.X, line2.beginPoint.Y);
                            //                    CGContextAddLineToPoint(context, bandRightEndPoint.X,bandRightEndPoint.Y);
                            CGContextAddLineToPoint(context, line2.endPoint.X,line2.endPoint.Y);
                            CGContextStrokePath(context);
                            [self.bandLineBeginList addObject:line2];
                            NSLog(@"\nbeginPointX=%f,beginPointY=%f,endPointX=%f,endPointY=%f",line2.beginPoint.X,line2.beginPoint.Y,line2.endPoint.X,line2.endPoint.Y);
                            
                            //                    [self.bandLineEndList addObject:[[[InterfacePoint alloc] initWithXY:bandRightEndPoint.X Y:bandRightEndPoint.Y] autorelease]];
                            
                            //                    [self.bandLineColorList addObject:[UIColor redColor]];
                            if (!bandWasIntterupted) {
                                const float* colors = CGColorGetComponents(lineColor2.CGColor);
                                UIColor *squareColor=[UIColor colorWithRed:colors[0] green:colors[1] blue:colors[2] alpha:0.5];
                                
                                CGContextSetRGBFillColor(context, colors[0], colors[1],colors[2], 0.5);
                                InterfaceSquareArea *square=[[InterfaceSquareArea alloc] initWithTopLeftPoint:lineBeginPoint topRightPoint:lineBeginPoint2 bottomLeftPoint:lineEndPoint bottomRightPoint:lineEndPoint2 color:squareColor];
                                CGContextBeginPath(context);
                                CGContextMoveToPoint   (context, square.topLeftPoint.X, square.topLeftPoint.Y);
                                CGContextAddLineToPoint(context, square.topRightPoint.X, square.topRightPoint.Y);
                                CGContextAddLineToPoint(context, square.bottomRightPoint.X, square.bottomRightPoint.Y);
                                CGContextAddLineToPoint(context, square.bottomLeftPoint.X, square.bottomLeftPoint.Y);
                                CGContextClosePath(context);
                                
                                CGContextFillPath(context);
                                [self.squareAreaList addObject:square];
                            }
                        }
                        

                        
                    }
                }
                if(afterLink)
                {
                    for (int k=0;k< label.wbandLeftEndPoints.count;k++) {
                        {
                            InterfacePoint *point =[label.wbandLeftEndPoints objectAtIndex:k];
                            InterfacePoint *endPoint=[label.wbandRightEndPoints objectAtIndex:k];
                            
                            Link *afterLink=label.afterLink;
                            if (!afterLink) {
                                continue;
                            }
                            
                            InterfacePoint *tempBandLeftBeginPoint=[[[InterfacePoint alloc] initWithXY:0 Y:0] autorelease];
                            InterfacePoint *tempBandLeftEndPoint=[[[InterfacePoint alloc] initWithXY:0 Y:0] autorelease];
                            InterfacePoint *tempBandRightBeginPoint=[[[InterfacePoint alloc] initWithXY:0 Y:0] autorelease];
                            InterfacePoint *tempBandRightEndPoint=[[[InterfacePoint alloc] initWithXY:0 Y:0] autorelease];
                            
                            {
                                tempBandLeftBeginPoint.X=point.X;
                                tempBandLeftBeginPoint.Y=point.Y+label.frame.origin.y+label.signalNameLabel.frame.size.height;
                                tempBandLeftEndPoint.X=point.X-[afterLink getOffsetX]*timeToPixel;
                                tempBandLeftEndPoint.Y=point.Y+[afterLink getOffsetY]+label.frame.origin.y+label.signalNameLabel.frame.size.height;
                                
                                tempBandRightBeginPoint.X=endPoint.X;
                                tempBandRightBeginPoint.Y=endPoint.Y+label.frame.origin.y+label.signalNameLabel.frame.size.height;
                                tempBandRightEndPoint.X=endPoint.X-[afterLink getOffsetX]*timeToPixel;
                                tempBandRightEndPoint.Y=endPoint.Y+[afterLink getOffsetY]+label.frame.origin.y+label.signalNameLabel.frame.size.height;
                                
                                UIColor *lineColor=[UIColor blueColor];
                                InterfaceLine * interfaceLine=[[[InterfaceLine alloc] initWithBeginPoint:tempBandLeftBeginPoint endPoint:tempBandLeftEndPoint color:lineColor] autorelease];
                                CGContextSetLineWidth(context, 2.0);
                                CGContextSetStrokeColor(context, CGColorGetComponents(lineColor.CGColor));
                                CGContextBeginPath(context);
                                //                                CGContextMoveToPoint(context, leftpoint.X, leftpoint.Y+nextLabel.frame.origin.y);
                                CGFloat dashArray[] = {2,6,4,2};
                                
                                CGContextSetLineDash(context, 3, dashArray, 4);
                                interfaceLine.dashed=YES;
                                CGContextMoveToPoint(context, interfaceLine.beginPoint.X,interfaceLine.beginPoint.Y);
                                //                                CGContextAddLineToPoint(context, leftpoint.X-[bLink getOffsetX], leftpoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y);
                                CGContextAddLineToPoint(context, interfaceLine.endPoint.X, interfaceLine.endPoint.Y);
                                CGContextStrokePath(context);
                                [self.bandLineBeginList addObject:interfaceLine];
                                CGContextSetLineDash(context, 0, nil, 0);
                            }
                            {
                                tempBandLeftBeginPoint.X=point.X;
                                tempBandLeftBeginPoint.Y=point.Y+label.frame.origin.y+label.signalNameLabel.frame.size.height;
                                tempBandLeftEndPoint.X=point.X-[afterLink getOffsetX]*timeToPixel;
                                tempBandLeftEndPoint.Y=point.Y+[afterLink getOffsetY]+label.frame.origin.y+label.signalNameLabel.frame.size.height;
                                
                                tempBandRightBeginPoint.X=endPoint.X;
                                tempBandRightBeginPoint.Y=endPoint.Y+label.frame.origin.y+label.signalNameLabel.frame.size.height;
                                tempBandRightEndPoint.X=endPoint.X-[afterLink getOffsetX]*timeToPixel;
                                tempBandRightEndPoint.Y=endPoint.Y+[afterLink getOffsetY]+label.frame.origin.y+label.signalNameLabel.frame.size.height;
                                
                                UIColor *lineColor=[UIColor blueColor];
                                InterfaceLine * interfaceLine=[[[InterfaceLine alloc] initWithBeginPoint:tempBandRightBeginPoint endPoint:tempBandRightEndPoint color:lineColor] autorelease];
                                CGContextSetLineWidth(context, 2.0);
                                CGContextSetStrokeColor(context, CGColorGetComponents(lineColor.CGColor));
                                CGContextBeginPath(context);
                                //                                CGContextMoveToPoint(context, leftpoint.X, leftpoint.Y+nextLabel.frame.origin.y);
                                CGFloat dashArray[] = {2,6,4,2};
                                
                                CGContextSetLineDash(context, 3, dashArray, 4);
                                interfaceLine.dashed=YES;
                                CGContextMoveToPoint(context, interfaceLine.beginPoint.X,interfaceLine.beginPoint.Y);
                                //                                CGContextAddLineToPoint(context, leftpoint.X-[bLink getOffsetX], leftpoint.Y-[bLink getOffsetY]+nextLabel.frame.origin.y);
                                CGContextAddLineToPoint(context, interfaceLine.endPoint.X, interfaceLine.endPoint.Y);
                                CGContextStrokePath(context);
                                [self.bandLineBeginList addObject:interfaceLine];
                                CGContextSetLineDash(context, 0, nil, 0);
                            }
                            
                            
                        }
                    }
                }

            }
                break;
                
            default:
                break;
        }
        
        
    }
    /*
     for (int i=self.dynamicSignalLabelList.count-2; i>=0; i--) {
     Link *beforeLink=label.beforeLink;
     Link *afterLink=label.afterLink;
     DynamicSignalLabel *label=[self.dynamicSignalLabelList objectAtIndex:i];
     if (afterLink) {
     for (InterfacePoint *point in label.bandLeftBeginPoints) {
     CGContextSetStrokeColor(context, green);
     CGContextBeginPath(context);
     CGContextMoveToPoint(context, point.X, point.Y+label.frame.origin.y);
     CGContextAddLineToPoint(context, point.X+[afterLink getOffsetX], point.Y+[afterLink getOffsetY]+label.frame.origin.y);
     CGContextStrokePath(context);
     }
     }
     
     }*/
    
    
    
}


@end
